#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> 
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include "app_platform/cntl_info.h"
#include "cooperatorao.h"

#include "app_platform/db_operator2.h"
#include "c2cplatform/library/the3/itil/c2c_attr.h"
#include "library/algorithm/algorithm.h"
#include "library/util/string_helper.h"

#include "b2b2c/library/tmem_client_new.h"
#include "b2b2c_define.h"
#include "b2b2c_errno_define.h"
#include "b2b2c/comm/item_tools.h"
#include "c2cplatform/tools/idmaker/handle_idmaker_4app.h"


#include "b2b2c/cooperator/dao/cooperatordao_stub4app_allinone.h"
#include "b2b2c/cooperatorevent/ao/cooperatoreventao_stub4app_allinone.h"
#include "b2b2c/nca/dao/ncadao_stub4app_allinone.h"
#include "b2b2c/cooperator/to/cooperator_baseinfo_conv.h"
#include "b2b2c/cooperator/to/cooperator_subaccount_conv.h"
#include "b2b2c/cooperator/to/cooperator_license_conv.h"
#include "b2b2c/comm/authorizationfield4app_comm.h"
#include "b2b2c/cooperator/cooperator_define.h"
#include "cooperatorao_enum.h"
#include "sellerdao_stub4app_allinone.h"


using namespace c2cent::library::wwlog;
using namespace c2cent::library::wtimeelf;
using namespace c2cplatform::library::algorithm;
using namespace c2cplatform::library::util;
using namespace b2b2c::comm;
using namespace b2b2c::comm::tools;
using namespace b2b2c::comm::tmem;
using namespace c2cplatform::tools::idmaker;

using namespace b2b2c::cooperator::ao;
using namespace b2b2c::cooperatorbaseinfo::to;
using namespace b2b2c::cooperatorsubaccount::to;
using namespace b2b2c::cooperatorlicense::to;
using namespace b2b2c::cooperator::po;
using namespace b2b2c::cooperator::ddo;
using namespace b2b2c::cooperator;


#define COOPERATOR_ID_ENTITY_KEY    0
#define COOPERATOR_LICENSE_ID_ENTITY_KEY    1
#define COOPERATOR_KEY_ID_ENTITY_KEY    2
#define COOPERATOR_TMEMCACHE_DEF_EXPIRE_TIME  90*3600*24
#define COOPERATOR_CMEM_PREFIX "Cooperator_"
#define COOPERATOR_KEY_CMEM_PREFIX "CooperatorKey_"
#define ICSON_ID_CMEM_PREFIX "IcsonID_"

#define COOPERATOR_MONITOR_CMEM_PREFIX "CooperatorMonitor_"
#define CONFIG_PRO_SEPARATOR ","

#define KEY_LOG_START        0
#define KEY_LOG_END          1

#define COOPERATOR_MONITOR_IDMAKER_TYPE 159 //告警模版类型

CItilGroup CCooperatorAo::m_oUpdateCooperatorBaseInfoGroup(ITIL_COOPERATOR_BASEINFO_UPDATE_REQ,ITIL_COOPERATOR_BASEINFO_UPDATE_ERR,ITIL_COOPERATOR_BASEINFO_UPDATE_RSP,ITIL_COOPERATOR_BASEINFO_UPDATE_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorLicenseGroup(ITIL_COOPERATOR_LICENSE_GET_REQ,ITIL_COOPERATOR_LICENSE_GET_ERR,ITIL_COOPERATOR_LICENSE_GET_RSP,ITIL_COOPERATOR_LICENSE_GET_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorBaseInfoGroup(ITIL_COOPERATOR_BASEINFO_GET_REQ,ITIL_COOPERATOR_BASEINFO_GET_ERR,ITIL_COOPERATOR_BASEINFO_GET_RSP,ITIL_COOPERATOR_BASEINFO_GET_DEF,TIME_REPORT);
CItilGroup CCooperatorAo::m_oSetCooperatorPassWdGroup(ITIL_COOPERATOR_PASSWD_SET_REQ,ITIL_COOPERATOR_PASSWD_SET_ERR,ITIL_COOPERATOR_PASSWD_SET_RSP,ITIL_COOPERATOR_PASSWD_SET_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oCheckCooperatorPassWdGroup(ITIL_COOPERATOR_PASSWD_CHECK_REQ,ITIL_COOPERATOR_PASSWD_CHECK_ERR,ITIL_COOPERATOR_PASSWD_CHECK_RSP,ITIL_COOPERATOR_PASSWD_CHECK_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oUpdateCooperatorLicenseGroup(ITIL_COOPERATOR_LICENSE_UPDATE_REQ,ITIL_COOPERATOR_LICENSE_UPDATE_ERR,ITIL_COOPERATOR_LICENSE_UPDATE_RSP,ITIL_COOPERATOR_LICENSE_UPDATE_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oSendCooperatorSubAccountInfoEventMsgq(ITIL_SEND_SUBACCOUNT_MSGQ_REQ,ITIL_SEND_SUBACCOUNT_MSGQ_ERR,ITIL_SEND_SUBACCOUNT_MSGQ_RSP,ITIL_SEND_SUBACCOUNT_MSGQ_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oSendCooperatorLicenseInfoEventMsgq(ITIL_SEND_COOPERATOR_LICENSE_MSGQ_REQ,ITIL_SEND_COOPERATOR_LICENSE_MSGQ_ERR,ITIL_SEND_COOPERATOR_LICENSE_MSGQ_RSP,ITIL_SEND_COOPERATOR_LICENSE_MSGQ_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorLicenseInfo4MsgQKeylog(ITIL_GET_COOPERATOR_LICENSE_LEKLOG_REQ,ITIL_GET_COOPERATOR_LICENSE_LEKLOG_ERR,ITIL_GET_COOPERATOR_LICENSE_LEKLOG_RSP,ITIL_GET_COOPERATOR_LICENSE_LEKLOG_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oSendCooperatorBaseInfoEventMsgq(ITIL_SEND_COOPERATOR_BASEINFO_MSGQ_REQ,ITIL_SEND_COOPERATOR_BASEINFO_MSGQ_ERR,ITIL_SEND_COOPERATOR_BASEINFO_MSGQ_RSP,ITIL_SEND_COOPERATOR_BASEINFO_MSGQ_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorBaseInfo4MsgQKeylog(ITIL_GET_COOPERATOR_BASEINFO_LEKLOG_REQ,ITIL_GET_COOPERATOR_BASEINFO_LEKLOG_ERR,ITIL_GET_COOPERATOR_BASEINFO_LEKLOG_RSP,ITIL_GET_COOPERATOR_BASEINFO_LEKLOG_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetNode(ITIL_GET_NCA_NODE_REQ,ITIL_GET_NCA_NODE_ERR,ITIL_GET_NCA_NODE_RSP,ITIL_GET_NCA_NODE_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorBaseInfoList(ITIL_GET_COOPERATOR_LIST_REQ,ITIL_GET_COOPERATOR_LIST_ERR,ITIL_GET_COOPERATOR_LIST_RSP,ITIL_GET_COOPERATOR_LIST_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorKey(ITIL_GET_COOPERATOR_KEY_REQ,ITIL_GET_COOPERATOR_KEY_ERR,ITIL_GET_COOPERATOR_KEY_RSP,ITIL_GET_COOPERATOR_KEY_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oLogisticsSetCooperatorPro(ITIL_LOGISTICS_SET_COOPERATOR_PRO_REQ,ITIL_LOGISTICS_SET_COOPERATOR_PRO_ERR,ITIL_LOGISTICS_SET_COOPERATOR_PRO_RSP,ITIL_LOGISTICS_SET_COOPERATOR_PRO_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oSetCooperatorInfo(ITIL_SET_COOPERATOR_INFO_REQ,ITIL_SET_COOPERATOR_INFO_ERR,ITIL_SET_COOPERATOR_INFO_RSP,ITIL_SET_COOPERATOR_INFO_DEF,TIME_50MS);

CItilGroup CCooperatorAo::m_oGetDataFromTmemGroup(0,ITIL_GET_COOPERATOR_CMEM_CACHE_ERR,0,0,0);
CItilGroup CCooperatorAo::m_oGetMonitorModelListGroup(ITIL_MINITOR_GET_MODELLIST_REQ,ITIL_MINITOR_GET_MODELLIST_ERR,ITIL_MINITOR_GET_MODELLIST_RSP,ITIL_MINITOR_GET_MODELLIST_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetMonitorModelGroup(ITIL_MINITOR_GET_MODEL_REQ,ITIL_MINITOR_GET_MODEL_ERR,ITIL_MINITOR_GET_MODEL_RSP,ITIL_MINITOR_GET_MODEL_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oUpdateMonitorModelGroup(ITIL_MINITOR_UPDATE_MODEL_REQ,ITIL_MINITOR_UPDATE_MODEL_ERR,ITIL_MINITOR_UPDATE_MODEL_RSP,ITIL_MINITOR_UPDATE_MODEL_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oDeleteMonitorModelGroup(ITIL_MINITOR_DEL_MODEL_REQ,ITIL_MINITOR_DEL_MODEL_ERR,ITIL_MINITOR_DEL_MODEL_RSP,ITIL_MINITOR_DEL_MODEL_DEF,TIME_50MS);
CItilGroup CCooperatorAo::m_oGetCooperatorIDGroup(ITIL_GET_COOPERATORID_BY_ICSONID_REQ,ITIL_GET_COOPERATORID_BY_ICSONID_ERR,ITIL_GET_COOPERATORID_BY_ICSONID_RSP,ITIL_GET_COOPERATORID_BY_ICSONID_DEF,TIME_50MS);

std::set<uint16_t> CCooperatorAo::m_setLogisticsPro;
std::string CCooperatorAo::m_monitorSysRule;//系统规则字符串
Json::Value CCooperatorAo::m_monitorRuleCfg;//规则配置情况
std::string CCooperatorAo::m_monitorRuleJson;//规则配置JSON字符串
std::map<std::string,Json::Value> CCooperatorAo::m_monitorRuleMap;

/**
 *构建函数
 */
CCooperatorAo::CCooperatorAo(enum DeployMethod method)
{


}

/**
 *析构函数
 */
CCooperatorAo::~CCooperatorAo()
{
}

/**
 *每一次服务请求时，container都会调用此方法来清空数据
 */
void  CCooperatorAo::Reset()
{
    m_dwOperatorUin=0;
    m_dwSceneId=0;
    m_strMachineKey="";
    m_strSource="";
}

int32_t CCooperatorAo::InitTMEM(IUserDefineCntl* pCntl){
    int32_t iRetCode = 0;
    std::string strTmemSvrName ="Cooperator_Tmem_Acc";
    uint32_t dwTmemBid = 102030068;
    std::map<TmemCacheItilEnum, uint32_t> mapTmemItil;
    uint64_t dwTmemExpireTime = COOPERATOR_TMEMCACHE_DEF_EXPIRE_TIME;
    uint32_t dwTmemReadSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemBatchReadSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemWriteSlowTime = TMEMCACHE_DEF_SLOW_TIME;
    uint32_t dwTmemBufferSize = TMEMCACHE_BUFFER_SIZE;
    uint32_t dwTmemUpdateAddrThreshold = TMEMCACHE_UPDATEADDR_THREDHOLD;
    bool bTmemUserNoKey = true;
    bool bTmemClosedCache = false;
    uint32_t dwTmemReadTimeout = TMEMCACHE_READ_TIMEOUT;
    uint32_t dwTmemFailedFreezeTime = TMEMCACHE_FAILED_FREEZE_TIME;
    uint32_t dwTmemConnectTimeout = TMEMCACHE_CONNECT_TIMEOUT;

    GetStringConfig(TmemSvrName);
    GetUintConfig(TmemBid);
    GetUintConfig(TmemExpireTime);
    GetUintConfig(TmemReadSlowTime);
    GetUintConfig(TmemBatchReadSlowTime);
    GetUintConfig(TmemWriteSlowTime);
    GetUintConfig(TmemBufferSize);
    GetUintConfig(TmemUpdateAddrThreshold);

    uint32_t dwTmemUserNoKey = 1;
    GetUintConfig(TmemUserNoKey);
    if(dwTmemUserNoKey != 0)
    {
        bTmemUserNoKey = true;
    }
    else
    {
        bTmemUserNoKey = false;
    }

    uint32_t dwTmemClosedCache = 0;
    GetUintConfig(TmemClosedCache);
    if(dwTmemClosedCache != 0)
    {
        bTmemClosedCache = true;
    }
    else
    {
        bTmemClosedCache = false;
    }

    GetUintConfig(TmemReadTimeout);
    GetUintConfig(TmemFailedFreezeTime);
    GetUintConfig(TmemConnectTimeout);

    uint32_t dwTmemWriteSlowItil = 617312;
    uint32_t dwTmemReadSlowItil = 617313;
    uint32_t dwTmemBatchReadSlowItil = 0;
    uint32_t dwTmemWriteErrorItil = 617314;
    uint32_t dwTmemReadErrorItil = 617315;
    uint32_t dwTmemBatchReadErrorItil = 0;
    uint32_t dwTmemWriteRequestItil = 617316;
    uint32_t dwTmemReadRequestItil = 617317;
    uint32_t dwTmemBatchReadRequestItil = 0;
    uint32_t dwTmemBatchReadCellRequestItil = 0;
    uint32_t dwTmemReadHitItil = 617318;
    uint32_t dwTmemBatchReadCellHitItil = 0;

    GetUintConfig(TmemWriteSlowItil);
    GetUintConfig(TmemReadSlowItil);
    GetUintConfig(TmemBatchReadSlowItil);
    GetUintConfig(TmemWriteErrorItil);
    GetUintConfig(TmemReadErrorItil);
    GetUintConfig(TmemBatchReadErrorItil);
    GetUintConfig(TmemWriteRequestItil);
    GetUintConfig(TmemReadRequestItil);
    GetUintConfig(TmemBatchReadRequestItil);
    GetUintConfig(TmemBatchReadCellRequestItil);
    GetUintConfig(TmemReadHitItil);
    GetUintConfig(TmemBatchReadCellHitItil);

    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_SLOW,  dwTmemWriteSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_SLOW, dwTmemReadSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_SLOW, dwTmemBatchReadSlowItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_ERR,  dwTmemWriteErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_ERR, dwTmemReadErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_ERR, dwTmemBatchReadErrorItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_WRITE_REQ,  dwTmemWriteRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_REQ, dwTmemReadRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_REQ, dwTmemBatchReadRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_CELL_REQ, dwTmemBatchReadCellRequestItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_READ_HIT, dwTmemReadHitItil));
    mapTmemItil.insert(std::map<TmemCacheItilEnum, uint32_t>::value_type(ITIL_BATCHREAD_CELL_HIT, dwTmemBatchReadCellHitItil));

    iRetCode = TMEM_CACHE_OP->Initialize(
            strTmemSvrName,
            dwTmemBid,
            mapTmemItil,
            dwTmemExpireTime,
            (uint16_t)dwTmemReadSlowTime,
            (uint16_t)dwTmemBatchReadSlowTime,
            (uint16_t)dwTmemWriteSlowTime,
            dwTmemBufferSize,
            dwTmemUpdateAddrThreshold,
            bTmemUserNoKey,
            bTmemClosedCache,
            dwTmemReadTimeout,
            dwTmemFailedFreezeTime,
            dwTmemConnectTimeout
    );

    if (0 != iRetCode)
    {
        std::cout << "TMEM_CACHE_OP Initialize() Failed!!" << std::endl;
        return -1;
    }
    else
    {
        std::cout << "TMEM_CACHE_OP Initialize Succ!" << std::endl;
    }
    return 0;
}

//初始化规则相关的数据
int32_t CCooperatorAo::InitMonitorRuleCfg(IUserDefineCntl* pCntl)
{
	//读取配置文件，转换成json对象
	std::string strMonitorRuleConfig = "/usr/local/c2csvc/svc/ao_cooperator/etc/monitorrulecfg.json";
	GetStringConfig(MonitorRuleConfig);

	//判断文件是否存在且可读
	if(access(strMonitorRuleConfig.c_str(), 4) != 0)
	{

		std::cout << "InitMonitorRuleCfg cannot find config file:"<< strMonitorRuleConfig << std::endl;
		return -1;
	}

	//读取文件
	std::ifstream ifs;
	ifs.open(strMonitorRuleConfig.c_str());
	if(!ifs.is_open())
	{
		std::cout << "InitMonitorRuleCfg cannot open file:"<< strMonitorRuleConfig << std::endl;
		return -1;
	}

	Json::Reader     reader;
	Json::FastWriter writer;
	if (!reader.parse(ifs, m_monitorRuleCfg, false))
	{
		std::cout << "InitMonitorRuleCfg parse to json faild"<< std::endl;
		ifs.close();//关闭
		return -1;
	}

	//规则的JSON字符串
	m_monitorRuleJson = writer.write(m_monitorRuleCfg);

	//打印出来json内容
	std::cout << "json content:" << m_monitorRuleJson << std::endl;
	ifs.close();//关闭

	//不符合格式规范
	if(!m_monitorRuleCfg.isMember("mo"))
	{
		std::cout << "config json Invalid has no memeber named mo"<< std::endl;
		return -1;
	}

	//解析配置文件 生成规则检查map
	Json::Value ruleMos = m_monitorRuleCfg["mo"];
	Json::Value::Members moMembers = ruleMos.getMemberNames();
	for(uint32_t imo = 0;imo < moMembers.size();imo++)
	{
		std::string moval = moMembers[imo];
		Json::Value ruleCos = ruleMos[moval]["co"];
		Json::Value::Members coMembers = ruleCos.getMemberNames();
		for(uint32_t ico = 0;ico < coMembers.size();ico++)
		{
			std::string coval = coMembers[ico];
			Json::Value ruleCms = ruleCos[coval]["cm"];
			Json::Value::Members cmMembers = ruleCms.getMemberNames();
			for(uint32_t icm = 0;icm < cmMembers.size();icm++)
			{
				std::string cmval = cmMembers[icm];
				Json::Value ruleCfg = ruleCms[cmval]["cv"];
				//检验ruleCfg是否符合要求，如果不合要求报错
				if(!ruleCfg.isMember("min") ||
				   !ruleCfg.isMember("max") ||
				   !ruleCfg.isMember("msg") ||
				   !ruleCfg.isMember("desc")
				)
				{
					std::cout << "InitMonitorRuleCfg Invalid rule config:"<< writer.write(ruleCfg) << std::endl;
					return -1;
				}
				std::stringstream mapkey;
				mapkey<<moval<<":"<<coval<<":"<<cmval;
				m_monitorRuleMap[mapkey.str()]=ruleCfg;
			}
		}

	}

	std::cout << "monitor rulesrule count:" << (m_monitorRuleMap.size()) << " ok " << std::endl;


	//生成系统规则
	//读取配置文件，转换成json对象
	std::string strSystemRule = "/usr/local/c2csvc/svc/ao_cooperator/etc/systemrule.json";
	GetStringConfig(SystemRule);
	//判断文件是否存在且可读
	if(access(strSystemRule.c_str(), 4) != 0)
	{

		std::cout << "InitMonitorRuleCfg cannot find systemrule file:"<< strSystemRule << std::endl;
		return -1;
	}

	//读取文件
	ifs.open(strSystemRule.c_str());
	if(!ifs.is_open())
	{
		std::cout << "InitMonitorRuleCfg cannot open file:"<< strSystemRule << std::endl;
		return -1;
	}

	Json::Value sysRuleList;//系统规则二维数组

	if (!reader.parse(ifs, sysRuleList, false))
	{
		std::cout << "InitMonitorRuleCfg parse systemrule to json faild"<< std::endl;
		ifs.close();//关闭
		return -1;
	}

	//规则的JSON字符串
	m_monitorSysRule = writer.write(sysRuleList);

	//打印出来json内容
	std::cout << "monitor sysrule:" << sysRuleList << std::endl;
	ifs.close();//关闭



	//std::cout << "struct system rule start"<< std::endl;
	//系统规则生成
	/* 变更后的库存价格比变更前库存价格变化超过70%
	 * 变更后的（具体地域）售价比变更前基准价格变化超过70%
	 * 变更后的（具体活动名称）售价比变更前基准价格变化超过70%
	 * 变更后的（具体自主营销）售价比变更前基准价格变化超过70%
	 * 规则结构[[{},{}],[{},{}],[{}]]


	Json::Value sysRuleUnit;//规则单元一维数组
	Json::Value ruleItem;//规则单元

	int loopkey=1;
	while(loopkey<5)
	{
		//清空
		ruleItem.clear();
		sysRuleUnit.clear();

		ruleItem["mo"]=Json::Value(loopkey);//1，2，3，4
		ruleItem["co"]=Json::Value(loopkey==1?3:2);//库存价格是变更钱，其他都是基准价
		ruleItem["cm"]=Json::Value(4);//都是变化百分比大于
		ruleItem["cv"]=Json::Value(70);//70%


		//加入系统规则中
		sysRuleUnit.append(ruleItem);
		sysRuleList.append(sysRuleUnit);
		loopkey++;
	}

	std::cout << "struct end"<< std::endl;
	//写入字符串中
	m_monitorSysRule = writer.write(sysRuleList);
	*/

	//std::cout << "monitor sysrule :" << m_monitorSysRule << std::endl;

	return 0;
}


int  CCooperatorAo::Initialize(IUserDefineCntl* pCntl)
{
    int32_t iRetCode = 0;
    uint32_t dwLogSwitch=WLOG_OPEN|WLOG_KEY_OPEN|WLOG_ERR_OPEN;

    uint32_t dwCanLogRemote = 0;
    std::string strLogModule="ao_cooperator";
    std::set<uint32_t> setUseCache;

    std::cout<<"File:"<<__FILE__<<" Complie Date: "<<__DATE__<<" "<<__TIME__<<std::endl;

    GetUintConfig(LogSwitch);
    GetStringConfig(LogModule);
    GetUintConfig(CanLogRemote);

    //-----外部业务合作伙伴属性设置接口的属性值操作权限配置
    //1、获取支付物流设置合作伙伴属性位权限配置
    std::string strLogisticsPro = "64,65";
    GetStringConfig(LogisticsPro);
    std::vector<std::string> vecStrLogisticsPro;
    CStringHelper::SplitStringIntoVector(strLogisticsPro.c_str(), CONFIG_PRO_SEPARATOR, vecStrLogisticsPro);
    std::vector<std::string>::const_iterator itVecStrLogisticsPro = vecStrLogisticsPro.begin();
    for(;itVecStrLogisticsPro!=vecStrLogisticsPro.end();itVecStrLogisticsPro++){
        m_setLogisticsPro.insert((uint16_t)atol((*itVecStrLogisticsPro).c_str()));
    }

    //初始化TMEM
    iRetCode = InitTMEM(pCntl);
    if(iRetCode != 0)
    {
        return iRetCode;
    }
    std::cout<<"InitTmem Initialize OK!"<<std::endl;

    //初始化规则配置文件
    iRetCode = InitMonitorRuleCfg(pCntl);
    if(iRetCode != 0)
	{
		return iRetCode;
	}
    std::cout<<"InitMonitorRuleCfg Initialize OK!"<<std::endl;

    //初始化IDMAKER
    IDMAKER_HANDLER->RegistNeedId(COOPERATOR_MONITOR_IDMAKER_TYPE,1000,0);

    iRetCode = IDMAKER_HANDLER->Initialize();
    if(iRetCode != 0)
    {
    	std::cout << "IDMAKER_HANDLER->Initialize Failed" << std::endl;
    	return iRetCode;
    }
    std::cout<<"IDMAKER_HANDLER Initialize OK!"<<std::endl;

    // 初始化日志
    if( C2C_WWLOG->QuickInitForAPP2(strLogModule.c_str(),B2B2CWW_LOG_APP_FILE_PATH, dwCanLogRemote, dwLogSwitch)!= 0)
    {
        std::cerr << "C2C_WWLOG->QuickInitForAPP2 Failed" << std::endl;
        return -1;
    }
    C2C_WW_LOG("C2C_WWLOG->QuickInitForAPP2 OK!");

    return 0;
}


/**
 *
 * 更新【新增和修改】合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorBaseInfoPo cooperatorBaseInfoPo: 合作伙伴基本信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::UpdateCooperatorBaseInfo(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    std::set<uint32_t> setEventId;
    std::set<uint32_t> setEventIdSubAccount;
    uint32_t dwOperationType = 0;
    std::stringstream oss;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    b2b2c::cooperator::po::CCooperatorBaseInfoPo oCooperatorBaseInfoPoBefore;
    b2b2c::cooperator::po::CCooperatorBaseInfoPo oCooperatorBaseInfoPoAfter;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateCooperatorBaseInfoGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId);

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    iRetCode=_ParameterCheckForBaseInfo(oCooperatorBaseInfoPo);
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo oCooperatorBaseInfoDdo;
    CCooperatorBaseInfoConv::Conv_CCooperatorBaseInfo_PoToDdo(oCooperatorBaseInfoPo, oCooperatorBaseInfoDdo); //合作伙伴基本信息转换
    const std::vector<CCooperatorSubAccountPo> &vecCooperatorSubAccountPo = oCooperatorBaseInfoPo.GetCooperatorSubAccountPo();
    std::vector<CCooperatorSubAccountDdo> &vecCooperatorSubAccountDdo = (std::vector<CCooperatorSubAccountDdo>&)oCooperatorBaseInfoDdo.GetCooperatorSubAccountDdo();
    CCooperatorSubAccountDdo oCooperatorSubAccountDdo;
    std::vector<CCooperatorSubAccountPo>::const_iterator it = vecCooperatorSubAccountPo.begin();
    for (; it != vecCooperatorSubAccountPo.end(); it++)
    {
        CCooperatorSubAccountConv::Conv_CCooperatorSubAccountPoToDdo(*it, oCooperatorSubAccountDdo); //合作伙伴子帐号信息转换
        vecCooperatorSubAccountDdo.push_back(oCooperatorSubAccountDdo);
    }

    //更新合作伙伴信息前记录keylog
    uint32_t dwRet = _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_START, oCooperatorBaseInfoPo.GetCooperatorId(),
                                        oCooperatorBaseInfoPoBefore, oWTimeElf);

    //更新合作伙伴信息
    iRetCode =  _UpdateCooperatorBaseInfo(rCntlInfo, oCooperatorBaseInfoDdo, oWTimeElf);
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新合作伙伴信息成功后，记录keylog
    _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_END, oCooperatorBaseInfoPo.GetCooperatorId(),
                                        oCooperatorBaseInfoPoAfter, oWTimeElf);

    if(dwRet==0)
    {
        setEventId.insert(COOPERATOR_EVENT_ID_BASEINFO_MODITY);
        dwOperationType = OP_MODIFY;

    }else{
        setEventId.insert(COOPERATOR_EVENT_ID_BASEINFO_ADD);
        dwOperationType = OP_ADD;
    }

    //发送msgq通知
    _SendSendCooperatorBaseInfoEventMsgq(rCntlInfo, m_dwSceneId, COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS, dwOperationType, setEventId, 0,
            oCooperatorBaseInfoPoBefore, oCooperatorBaseInfoPoAfter, oWTimeElf);

    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo> &vecCooperatorSubAccountPoBefore =
            oCooperatorBaseInfoPoBefore.GetCooperatorSubAccountPo();
    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo> &vecCooperatorSubAccountPoAfter =
            oCooperatorBaseInfoPoAfter.GetCooperatorSubAccountPo();
    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>::iterator itSubAccountPoBefore;
    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>::iterator itSubAccountPoAfter;

    for(itSubAccountPoAfter=vecCooperatorSubAccountPoAfter.begin();
            itSubAccountPoAfter!=vecCooperatorSubAccountPoAfter.end();
            itSubAccountPoAfter++)
    {
        itSubAccountPoBefore = find(vecCooperatorSubAccountPoBefore.begin(),
                vecCooperatorSubAccountPoBefore.end(), (*itSubAccountPoAfter));
        if( itSubAccountPoBefore == vecCooperatorSubAccountPoBefore.end())
        {
            //没有找到，新增的子帐号
            setEventIdSubAccount.insert(COOPERATOR_EVENT_ID_SUBACCOUNT_ADD);
        }else
        {
            //判断子帐号信息是否有发生变化
            if( (*itSubAccountPoAfter).GetCooperatorSubAccountState() !=
                    (*itSubAccountPoBefore).GetCooperatorSubAccountState())
            {
                setEventIdSubAccount.insert(COOPERATOR_EVENT_ID_SUBACCOUNT_MODIFY);
            }

            if( (*itSubAccountPoAfter).GetCooperatorSubAccountProperty() !=
                    (*itSubAccountPoBefore).GetCooperatorSubAccountProperty())
            {
                setEventIdSubAccount.insert(COOPERATOR_EVENT_ID_SUBACCOUNT_MODIFY);
            }
        }
    }

    //判断发送子帐号Msgq通知
    if( 0 != setEventIdSubAccount.size())
    {
        _SendSendCooperatorSubAccountInfoEventMsgq(rCntlInfo, 0xA0121804, COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS, OP_MODIFY,
                setEventIdSubAccount, 0, vecCooperatorSubAccountPoBefore, vecCooperatorSubAccountPoAfter, oWTimeElf);
    }

    C2C_WW_LOG("%s Finished OpUin:%u MachineKey:%s Source:%s SceneId:%u", __FUNCTION__, m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId);
    return 0;
}

/**
 *
 * 获取合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param Set licenseType: 许可证类型，为空则为全部许可证列表  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param Vector cooperatorLicenseDdo: 合作伙伴许可证信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorLicense(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::set<uint8_t >& setLicenseType,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::vector<b2b2c::cooperator::po::CCooperatorLicensePo >& vecCooperatorLicensePo,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    uint32_t i;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorLicenseGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%lu",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, ddwCooperatorId);

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //读db
    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo > vecCooperatorLicenseDdo;
    iRetCode = oCooperatorDaoStub4App.GetCooperatorLicense(rCntlInfo, strMachineKey, strSource,
                                    dwSceneId, ddwCooperatorId, setLicenseType, strInReserve, strErrmsg,
                                    vecCooperatorLicenseDdo, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "GetCooperatorLicense Failed "
                                "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                dwSceneId, strErrmsg.c_str());
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //输出数据转换
    for(i=0; i<vecCooperatorLicenseDdo.size(); i++)
    {
        b2b2c::cooperator::po::CCooperatorLicensePo oCooperatorLicensePo;
        CCooperatorLicenseConv::Conv_CCooperatorLicense_DdoToPo(vecCooperatorLicenseDdo[i], oCooperatorLicensePo);
        vecCooperatorLicensePo.push_back(oCooperatorLicensePo);
    }

    C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  CooperatorId:%lu", __FUNCTION__,
            m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, ddwCooperatorId);
    return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorBaseInfoPo cooperatorBaseInfoPo: 合作伙伴基本信息，必填；新增时，必须新增合作伙伴信息，然后增加子帐号信息；必须先新增合作伙伴；如只更新合作伙伴子帐号信息，则只需传入合作伙伴ID和对应的子帐号信息列表  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorBaseInfo(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    uint32_t i;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCacheExpireTime = 0;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)?
                              ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorBaseInfoGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, ddwCooperatorId);

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    if( dwCooperatorId < 10000 ){
        C2C_WW_LOG_ERR(ERR_COOPERATORID_INVALID, "GetCooperatorBaseInfo Failed "
                                     "OpUin:%u MachineKey:%s Source:%s SceneId:%u ddwCooperatorId:%lu ErrMsg:%s",
                                     m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                     dwSceneId, ddwCooperatorId, strErrmsg.c_str());
        return ERR_COOPERATORID_INVALID;
    }

    Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_REQ,1);
    b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo oCooperatorBaseInfoDdo;
    std::stringstream ssKey;
    ssKey << COOPERATOR_CMEM_PREFIX;
    ssKey << dwCooperatorId;
    iRetCode = TMEM_CACHE_OP->GetData(ssKey.str(), oCooperatorBaseInfoDdo, dwCacheExpireTime);
    oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->GetData", iRetCode );
    if(0!=iRetCode){
        //调用DAO
        Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_ERR,1);
        b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
        iRetCode = oCooperatorDaoStub4App.GetCooperatorBaseInfo(rCntlInfo, strMachineKey, strSource,
                            dwSceneId, ddwCooperatorId, strInReserve, strErrmsg, oCooperatorBaseInfoDdo,
                            strOutReserve);
        if(iRetCode != 0)
        {
            C2C_WW_LOG_ERR(iRetCode, "GetCooperatorBaseInfo Failed "
                                    "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s ddwCooperatorId:%lu",
                                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                    dwSceneId, strErrmsg.c_str(), ddwCooperatorId);
            C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
            return iRetCode;
        }
    }

    //输出数据转换
    CCooperatorBaseInfoConv::Conv_CCooperatorBaseInfo_DdoToPo_Simple(oCooperatorBaseInfoDdo, oCooperatorBaseInfoPo);
    std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo> vecCooperatorSubAccountDdo = oCooperatorBaseInfoDdo.GetCooperatorSubAccountDdo();
    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo> vecCooperatorSubAccountPo;
    for(i=0; i<vecCooperatorSubAccountDdo.size(); i++)
    {
        b2b2c::cooperator::po::CCooperatorSubAccountPo oCooperatorSubAccountPo;
        CCooperatorSubAccountConv::Conv_CCooperatorSubAccountDdoToPo(vecCooperatorSubAccountDdo[i], oCooperatorSubAccountPo);
#if 0
        b2b2c::nca::ddo::CNavDdo navDdo;
        iRetCode = _GetNode(rCntlInfo, oCooperatorSubAccountPo.GetNavId(), navDdo, oWTimeElf);
        if(iRetCode!=0){
            //告警
            C2C_WW_LOG_ERR(iRetCode, "GetCooperatorBaseInfo Failed "
                                    "OpUin:%u MachineKey:%s Source:%s SceneId:%u NavId:%u ErrMsg:%s",
                                    m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                    dwSceneId, oCooperatorSubAccountPo.GetNavId(), strErrmsg.c_str());
        }else{
            oCooperatorSubAccountPo.SetNavName(navDdo.GetNavNode().GetName());
        }
#endif
        vecCooperatorSubAccountPo.push_back(oCooperatorSubAccountPo);
    }
    oCooperatorBaseInfoPo.SetCooperatorSubAccountPo(vecCooperatorSubAccountPo);
    C2C_WW_LOG("%s Finished, CooperatorId:%u ddwCooperatorId:%lu", __FUNCTION__, dwCooperatorId, ddwCooperatorId);
    return 0;
}

/**
 *
 * 设置合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorOldPassword: 合作伙伴老密码（三次MD5加密），必填  [in]
 *@param String cooperatorNewPassword: 合作伙伴新密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::SetCooperatorPassWd(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strCooperatorOldPassword,
				const std::string& strCooperatorNewPassword,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oSetCooperatorPassWdGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorOldPassword:%s CooperatorNewPassword:%s",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId,
            strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, ddwCooperatorId:%lu strCooperatorOldPassword:%s strCooperatorNewPassword:%s ", __FUNCTION__,
                    ddwCooperatorId, strCooperatorOldPassword.c_str(), strCooperatorNewPassword.c_str());
    return 0;
}


/**
 *
 * 检查合作伙伴密码信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String cooperatorPassword: 合作伙伴密码（三次MD5加密），必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::CheckCooperatorPassWd(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwCooperatorId,
				const std::string& strCooperatorPassword,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oCheckCooperatorPassWdGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorPassword:%s",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, strCooperatorPassword.c_str());

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //调用DAO
    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    iRetCode = oCooperatorDaoStub4App.CheckCooperatorPassWd(rCntlInfo, strMachineKey, strSource,
                                    dwSceneId, ddwCooperatorId, strCooperatorPassword,
                                    strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "CheckCooperatorPassWd Failed "
                                 "OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorPassword:%s ErrMsg:%s",
                                 m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId,
                                 strCooperatorPassword.c_str(), strErrmsg.c_str());
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    C2C_WW_LOG("%s Finished, ddwCooperatorId:%lu strCooperatorPassword:%s ", __FUNCTION__,
                    ddwCooperatorId, strCooperatorPassword.c_str());
    return 0;
}

/**
 *
 * 更新【新增和修改】合作伙伴许可证信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorLicensePo cooperatorLicensePo: 合作伙伴许可证信息，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::UpdateCooperatorLicense(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::po::CCooperatorLicensePo& oCooperatorLicensePo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
    int32_t iRetCode = 0;
    uint32_t dwRet = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    std::set<uint32_t> setEventId;

    std::vector<b2b2c::cooperator::po::CCooperatorLicensePo> vecCooperatorLicensePoBefore;
    std::vector<b2b2c::cooperator::po::CCooperatorLicensePo> vecCooperatorLicensePoAfter;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateCooperatorLicenseGroup);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId);

    iRetCode=_CheckRequest();
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    iRetCode = _ParameterCheckForLicense(oCooperatorLicensePo);
    if(0!=iRetCode)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新前记录keylog
    dwRet = _GetCooperatorLicenseInfo4MsgQKeylog(rCntlInfo, KEY_LOG_START, oCooperatorLicensePo.GetCooperatorId(),
                                            vecCooperatorLicensePoBefore, strOutReserve, oWTimeElf);

    //读db
    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    b2b2c::cooperator::ddo::CCooperatorLicenseDdo oCooperatorLicenseDdo;
    CCooperatorLicenseConv::Conv_CCooperatorLicense_PoToDdo(oCooperatorLicensePo, oCooperatorLicenseDdo);
    iRetCode = oCooperatorDaoStub4App.UpdateCooperatorLicense(rCntlInfo, strMachineKey, strSource,
                        dwSceneId, oCooperatorLicenseDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "UpdateCooperatorLicense Failed "
                                 "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                                 m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                 dwSceneId, strErrmsg.c_str());
       C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
       return iRetCode;
    }

    //更新后记录keylog
    _GetCooperatorLicenseInfo4MsgQKeylog(rCntlInfo, KEY_LOG_END, oCooperatorLicensePo.GetCooperatorId(),
            vecCooperatorLicensePoAfter, strOutReserve, oWTimeElf);

    //发送MSGQ
    if( 0 != dwRet )
    {
        setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_MODITY);
    }else
    {
        setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_ADD);
    }
    _SendSendCooperatorLicenseInfoEventMsgq(rCntlInfo, m_dwSceneId, COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS, OP_MODIFY,
                            setEventId, 0, vecCooperatorLicensePoBefore, vecCooperatorLicensePoAfter, oWTimeElf);

    C2C_WW_LOG("%s Finished, CooperatorId:%u", __FUNCTION__, oCooperatorLicensePo.GetCooperatorId());
    return 0;
}

/**
 *
 * 批量获取合作伙伴基本信息
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param Set cooperatorId: 合作伙伴Id_List，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param Vector cooperatorBaseInfoPo: 批量获取的合作伙伴基本信息List     [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorBaseInfoList(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                const std::set<uint64_t >& setCooperatorId,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::vector<b2b2c::cooperator::po::CCooperatorBaseInfoPo >& vecCooperatorBaseInfoPo,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    int32_t iFinalRetCode = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorBaseInfoList);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId);

    b2b2c::cooperator::po::CCooperatorBaseInfoPo oCooperatorBaseInfoPo;
    for(std::set<uint64_t>::const_iterator it = setCooperatorId.begin(); it != setCooperatorId.end(); it++)
    {
        C2C_WW_LOG("GetAReq %s ddwCooperatorId:%lu", __FUNCTION__, *it);
        iRetCode = GetCooperatorBaseInfo(rCntlInfo, strMachineKey, strSource, dwSceneId, *it, strInReserve,
                                    strErrmsg, oCooperatorBaseInfoPo, strOutReserve);
        if(iRetCode!=0)
        {
            C2C_WW_LOG_ERR(iRetCode, "%s GetCooperatorBaseInfo error, ddwCooperatorId:%lu RetCode:%d",
                                    __FUNCTION__, *it, iRetCode);
            iFinalRetCode = iRetCode;
            break;
        }
        vecCooperatorBaseInfoPo.push_back(oCooperatorBaseInfoPo);
    }

    C2C_WW_LOG_KEY("%s Finished", __FUNCTION__);
    return iFinalRetCode;
}

/**
 *
 * 获取合作伙伴数据加密Key
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息    [out]
 *@param String sCooperatorKey: 合作伙伴数据加密Key，长度32bytes；生成规则：合作伙伴当前密码三次MD5加密后的值   [out]
 *@param String outReserve: 请求保留字段  [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorKey(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwCooperatorId,
                const std::string& strInReserve,
                std::string& strErrmsg,
                std::string& strSCooperatorKey,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    uint32_t dwCacheExpireTime = 0;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCooperatorId = (uint32_t)(((ddwCooperatorId>>32) & 0x00000000FFFFFFFF)?
                           ((ddwCooperatorId>>32) & 0x00000000FFFFFFFF):ddwCooperatorId);

    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorKey);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
         __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId);

    Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_REQ,1);
    std::stringstream ssKey;
    ssKey << COOPERATOR_KEY_CMEM_PREFIX;
    ssKey << ddwCooperatorId;
    iRetCode = TMEM_CACHE_OP->GetSimpleData(ssKey.str(), strSCooperatorKey, dwCacheExpireTime);
    oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->GetData", iRetCode );
    if(0!=iRetCode){
        //调用DAO
        Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_ERR,1);
        b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
        iRetCode = oCooperatorDaoStub4App.GetCooperatorKey(rCntlInfo, strMachineKey, strSource,
                         dwSceneId, ddwCooperatorId, strInReserve, strErrmsg, strSCooperatorKey,
                         strOutReserve);
        if(iRetCode != 0)
        {
            C2C_WW_LOG_ERR(iRetCode, "GetCooperatorKey Failed "
                             "OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u ErrMsg:%s",
                             m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                             dwSceneId, dwCooperatorId, strErrmsg.c_str());
            C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
            return iRetCode;
        }
    }

    C2C_WW_LOG("%s Finished, CooperatorId:%u ddwCooperatorId:%lu", __FUNCTION__, dwCooperatorId, ddwCooperatorId);
    return 0;
}

/**
 *
 * 支付物流系统设置卖家的次日达，货到付款等属性位接口
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t option: 选项,暂未用  [in]
 *@param CooperatorProPo cooperatorProPo: 合作伙伴属性位设置，包括合作伙伴ID、设置和取消属性值设置的参数（设置和取消的属性位不能冲突），必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param CooperatorBaseInfoPo cooperatorBaseInfoPo: bitset作为回autogen生成的代码有问题，这里定义成po的形式，请取其中的cooperatorproperty属性值字段    [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::LogisticsSetCooperatorPro(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwOption,
                const b2b2c::cooperator::po::CCooperatorProPo& oCooperatorProPo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    std::set<uint32_t> setEventId;
    std::stringstream oss;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;

    b2b2c::cooperator::po::CCooperatorBaseInfoPo oCooperatorBaseInfoPoBefore;
    oCooperatorProPo.DumpData(oss);
    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oLogisticsSetCooperatorPro);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorProPo:%s",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, oss.str().c_str());

    iRetCode=_CheckRequest();
    if(iRetCode)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    iRetCode = _ParameterCheckCooperatorProPo(oCooperatorProPo);
    if(iRetCode){
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新合作伙伴信息前记录keylog
    uint32_t dwRet = _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_START, oCooperatorProPo.GetCooperatorId(),
                                                        oCooperatorBaseInfoPoBefore, oWTimeElf);
    if(dwRet){
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新合作伙伴信息
    b2b2c::cooperator::ddo::CCooperatorProDdo oCooperatorProDdo;
    CCooperatorBaseInfoConv::Conv_CCooperatorPro_PoToDdo(oCooperatorProPo, oCooperatorProDdo); //合作伙伴基本信息转换
    std::bitset<128>& bsExclude = (std::bitset<128> &)oCooperatorProDdo.GetBitExclude();
    //根据接口功能屏蔽掉无权设置的属性位
    for(size_t i = 0; i < bsExclude.size(); ++i)
    {
        if(bsExclude.test(i) && m_setLogisticsPro.find(i)==m_setLogisticsPro.end() )
        {
            bsExclude.reset(i);
        }
    }
    std::bitset<128>& bsInclude = (std::bitset<128> &)oCooperatorProDdo.GetBitInclude();
    //根据接口功能屏蔽掉无权设置的属性位
    for(size_t i = 0; i < bsInclude.size(); ++i)
    {
        if(bsInclude.test(i) && m_setLogisticsPro.find(i)==m_setLogisticsPro.end() )
        {
            bsInclude.reset(i);
        }
    }
    iRetCode =  _SetCooperatorPro(rCntlInfo, ddwOption, oCooperatorProDdo, oWTimeElf);
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新合作伙伴信息成功后，记录keylog
    _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_END, oCooperatorProPo.GetCooperatorId(),
                                        oCooperatorBaseInfoPo, oWTimeElf);

    //发送msgq通知
    setEventId.insert(COOPERATOR_EVENT_ID_BASEINFO_MODITY);
    _SendSendCooperatorBaseInfoEventMsgq(rCntlInfo, m_dwSceneId, COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS, OP_MODIFY, setEventId, 0,
                                            oCooperatorBaseInfoPoBefore, oCooperatorBaseInfoPo, oWTimeElf);

    C2C_WW_LOG("%s Finished OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorProPo:%s",
                    __FUNCTION__, m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, oss.str().c_str());
    return 0;
}

int32_t CCooperatorAo::_CheckRequest()
{
    if(m_strSource.empty()||m_strMachineKey.empty())
    {
        C2C_WW_LOG_ERR_ITIL(
                ERR_B2B2C_APP_SOURCE_OR_MACHINEKEY_EMPTY,
                ITIL_COOPERATOR_AO_PARAM,
                "SourceOrMachineKey Null OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);
        return ERR_B2B2C_APP_SOURCE_OR_MACHINEKEY_EMPTY;
    }

    return 0;
}

int32_t CCooperatorAo::_ParameterCheckCooperatorProPo(
                        const b2b2c::cooperator::po::CCooperatorProPo& oCooperatorProPo)
{
    uint32_t i;
    if( !oCooperatorProPo.IsCooperatorIdSet() || oCooperatorProPo.GetCooperatorId() < 10000)
    {
        C2C_WW_LOG_ERR_ITIL(
                ERR_COOPERATORID_INVALID,
                ITIL_COOPERATOR_AO_PARAM,
                "CooperatorId not set or invalid, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, oCooperatorProPo.GetCooperatorId());
        return ERR_COOPERATORID_INVALID;
    }

    if( !(( oCooperatorProPo.IsBitExcludeSet()
            || oCooperatorProPo.IsBitIncludeSet())))
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_EMPTY,
                        ITIL_COOPERATOR_AO_PARAM,
                        "no Cooperator filed to update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);
        return ERR_COOPERATOR_EMPTY;
    }

    //判断设置和取消标志位是否有冲突
    if( oCooperatorProPo.IsBitExcludeSet() && oCooperatorProPo.IsBitIncludeSet() ){
        const std::bitset<128> &bitsetExclude = oCooperatorProPo.GetBitExclude();
        const std::bitset<128> &bitsetInclude = oCooperatorProPo.GetBitInclude();
        for(i=0; i<128; i++){
           if(bitsetExclude.test(i) && bitsetInclude.test(i)){
               C2C_WW_LOG_ERR_ITIL(
                           ERR_COOPERATOR_PRO_CONFLICT,
                           ITIL_COOPERATOR_AO_PARAM,
                           "Cooperator set Property Conflict, OpUin:%u MachineKey:%s Source:%s SceneId:%u ProIndex:%u",
                           m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, i);
               return ERR_COOPERATOR_PRO_CONFLICT;
           }
        }
    }

    return 0;
}

int32_t CCooperatorAo::_ParameterCheckCooperatorSubProPo(
                        const b2b2c::cooperator::po::CCooperatorSubProPo& oCooperatorSubProPo)
{
    uint32_t i;
    if( !oCooperatorSubProPo.IsCooperatorIdSet() || oCooperatorSubProPo.GetCooperatorId() < 10000)
    {
        C2C_WW_LOG_ERR_ITIL(
                ERR_COOPERATORID_INVALID,
                ITIL_COOPERATOR_AO_PARAM,
                "CooperatorId not set or invalid, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, oCooperatorSubProPo.GetCooperatorId());
        return ERR_COOPERATORID_INVALID;
    }

    if( !(( oCooperatorSubProPo.IsBitExcludeSet()
            || oCooperatorSubProPo.IsBitIncludeSet())))
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_EMPTY,
                        ITIL_COOPERATOR_AO_PARAM,
                        "no Cooperator filed to update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);
        return ERR_COOPERATOR_EMPTY;
    }

    //判断设置和取消标志位是否有冲突
    if( oCooperatorSubProPo.IsBitExcludeSet() && oCooperatorSubProPo.IsBitIncludeSet() ){
        const std::bitset<128> &bitsetExclude = oCooperatorSubProPo.GetBitExclude();
        const std::bitset<128> &bitsetInclude = oCooperatorSubProPo.GetBitInclude();
        for(i=0; i<128; i++){
           if(bitsetExclude.test(i) && bitsetInclude.test(i)){
               C2C_WW_LOG_ERR_ITIL(
                           ERR_COOPERATOR_PRO_CONFLICT,
                           ITIL_COOPERATOR_AO_PARAM,
                           "Cooperator set Property Conflict, OpUin:%u MachineKey:%s Source:%s SceneId:%u ProIndex:%u",
                           m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, i);
               return ERR_COOPERATOR_PRO_CONFLICT;
           }
        }
    }

    return 0;
}

int32_t CCooperatorAo::_ParameterCheckForBaseInfo(
                        const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo)
{
    uint32_t i;

    if( !oCooperatorBaseInfoPo.IsCooperatorIdSet() || oCooperatorBaseInfoPo.GetCooperatorId() < 10000)
    {
        C2C_WW_LOG_ERR_ITIL(
                ERR_COOPERATORID_INVALID,
                ITIL_COOPERATOR_AO_PARAM,
                "CooperatorId not set, OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorId:%u",
                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, oCooperatorBaseInfoPo.GetCooperatorId());
        return ERR_COOPERATORID_INVALID;
    }

    if( !((oCooperatorBaseInfoPo.IsCooperatorNameSet()
            || oCooperatorBaseInfoPo.IsCooperatorLegalPersonSet()
            || oCooperatorBaseInfoPo.IsCooperatorAddressSet()
            || oCooperatorBaseInfoPo.IsCooperatorPhoneSet()
            || oCooperatorBaseInfoPo.IsCooperatorFaxSet()
            || oCooperatorBaseInfoPo.IsCooperatorEmailSet()
            || oCooperatorBaseInfoPo.IsCooperatorTypeSet()
            || oCooperatorBaseInfoPo.IsCooperatorSpidSet()
            || oCooperatorBaseInfoPo.IsCooperatorPropertySet()
            || oCooperatorBaseInfoPo.IsCooperatorStateSet()
            || oCooperatorBaseInfoPo.IsCooperatorSubAccountPoSet()
            || oCooperatorBaseInfoPo.IsContractNoSet()
            || oCooperatorBaseInfoPo.IsOrgIdSet()
            || oCooperatorBaseInfoPo.IsOrgFullNameSet()
            || oCooperatorBaseInfoPo.IsCvIdSet()
            || oCooperatorBaseInfoPo.IsCvNameSet()
            || oCooperatorBaseInfoPo.IsBitExcludeSet()
            || oCooperatorBaseInfoPo.IsBitIncludeSet())))
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_EMPTY,
                        ITIL_COOPERATOR_AO_PARAM,
                        "no Cooperator filed to update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);
        return ERR_COOPERATOR_EMPTY;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorNameSet() &&
        GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorName()) > MAX_LENGTH_COOPERATOR_NAME)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_NAME_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorName length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorName:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorName().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorName().length(), MAX_LENGTH_COOPERATOR_NAME);
        return ERR_COOPERATOR_NAME_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorLegalPersonSet() &&
        GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorLegalPerson()) > MAX_LENGTH_COOPERATOR_LEGAL_PERSON)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_LEGAL_PERSON_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorLegalPerson length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorLegalPerson:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorLegalPerson().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorLegalPerson().length(),
                        MAX_LENGTH_COOPERATOR_LEGAL_PERSON);
        return ERR_COOPERATOR_LEGAL_PERSON_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorAddressSet() &&
        GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorAddress()) > MAX_LENGTH_COOPERATOR_ADDRESS)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_ADDRESS_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorAddress length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorAddress:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorAddress().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorAddress().length(),
                        MAX_LENGTH_COOPERATOR_ADDRESS);
        return ERR_COOPERATOR_ADDRESS_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorPhoneSet() &&
        GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorPhone()) > MAX_LENGTH_COOPERATOR_PHONE)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_PHONE_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorPhone length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorPhone:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorPhone().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorPhone().length(),
                        MAX_LENGTH_COOPERATOR_PHONE);
        return ERR_COOPERATOR_PHONE_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorFaxSet() &&
            GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorFax()) > MAX_LENGTH_COOPERATOR_FAX)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_FAX_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorFax length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorFax:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorFax().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorFax().length(),
                        MAX_LENGTH_COOPERATOR_FAX);
        return ERR_COOPERATOR_FAX_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorEmailSet() &&
                GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorEmail()) > MAX_LENGTH_COOPERATOR_EMAIL)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_EMAIL_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorEmail length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorEmail:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorEmail().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorEmail().length(),
                        MAX_LENGTH_COOPERATOR_EMAIL);
        return ERR_COOPERATOR_EMAIL_LENGTH;
    }

    if( oCooperatorBaseInfoPo.IsCooperatorSpidSet() &&
                    GetUTF8LogicStrLen(oCooperatorBaseInfoPo.GetCooperatorSpid()) > MAX_LENGTH_COOPERATOR_SPID)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_COOPERATOR_SPID_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorSpid length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorSpid:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorBaseInfoPo.GetCooperatorSpid().c_str(),
                        oCooperatorBaseInfoPo.GetCooperatorSpid().length(),
                        MAX_LENGTH_COOPERATOR_SPID);
        return ERR_COOPERATOR_SPID_LENGTH;
    }

    if(oCooperatorBaseInfoPo.IsCooperatorSubAccountPoSet())
    {
        for(i=0; i<oCooperatorBaseInfoPo.GetCooperatorSubAccountPo().size(); i++)
        {
            if( !oCooperatorBaseInfoPo.GetCooperatorSubAccountPo()[i].IsCooperatorSubAccountIdSet() )
            {
                C2C_WW_LOG_ERR_ITIL(
                                ERR_COOPERATOR_EMPTY,
                                ITIL_COOPERATOR_AO_PARAM,
                                "no Cooperator data to update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
                                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);
                return ERR_COOPERATOR_ITEM_LACK;
            }else
            {
                if( oCooperatorBaseInfoPo.GetCooperatorSubAccountPo()[i].GetCooperatorSubAccountId() == 0 )
                {
                    C2C_WW_LOG_ERR_ITIL(
                                    ERR_SUBACCOUNT_INVALID,
                                    ITIL_COOPERATOR_AO_PARAM,
                                    "subaccount id error, OpUin:%u MachineKey:%s Source:%s SceneId:%u"
                                    " CooperatorSubAccountId:%lu ",
                                    m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId,
                                    oCooperatorBaseInfoPo.GetCooperatorSubAccountPo()[i].GetCooperatorSubAccountId());
                    return ERR_SUBACCOUNT_INVALID;
                }
            }
        }
    }

    return 0;
}

int32_t CCooperatorAo::_ParameterCheckForLicense(
                        const b2b2c::cooperator::po::CCooperatorLicensePo& oCooperatorLicensePo)
{
    if( oCooperatorLicensePo.IsLicenseCodeSet() &&
        GetUTF8LogicStrLen(oCooperatorLicensePo.GetLicenseCode()) > MAX_LENGTH_LICENSE_CODE)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_LICENSE_CODE_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "LicenseCode length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "LicenseCode:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorLicensePo.GetLicenseCode().c_str(),
                        oCooperatorLicensePo.GetLicenseCode().length(),
                        MAX_LENGTH_LICENSE_CODE);
        return ERR_LICENSE_CODE_LENGTH;
    }

    if( oCooperatorLicensePo.IsCooperatorScopeSet() &&
        GetUTF8LogicStrLen(oCooperatorLicensePo.GetCooperatorScope()) > MAX_LENGTH_LICENSE_SCOPE)
    {
        C2C_WW_LOG_ERR_ITIL(
                        ERR_LICENSE_SCOPE_LENGTH,
                        ITIL_COOPERATOR_AO_PARAM,
                        "CooperatorScope length Error OpUin:%u MachineKey:%s Source:%s SceneId:%u "
                        "CooperatorScope:%s Length:%zd MaxLength:%u",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,
                        oCooperatorLicensePo.GetCooperatorScope().c_str(),
                        oCooperatorLicensePo.GetCooperatorScope().length(),
                        MAX_LENGTH_LICENSE_SCOPE);
        return ERR_LICENSE_SCOPE_LENGTH;
    }

    return 0;
}

int32_t CCooperatorAo::_UpdateCooperatorBaseInfo(const CCntlInfo& rCntlInfo,
                                const b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo oCooperatorBaseInfoDdo,
                                c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    std::string strInReserve = "";
    std::string strErrmsg = "";
    std::string strOutReserve = "";

    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    iRetCode = oCooperatorDaoStub4App.UpdateCooperatorBaseInfo(rCntlInfo, m_strMachineKey, m_strSource, m_dwSceneId,
                        oCooperatorBaseInfoDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "UpdateCooperatorBaseInfo Failed "
                        "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(),
                        m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str());
    }

   return iRetCode;
}

int32_t CCooperatorAo::_SetCooperatorPro(const CCntlInfo& rCntlInfo,
                                uint64_t ddwOption,
                                const b2b2c::cooperator::ddo::CCooperatorProDdo& oCooperatorProDdo,
                                c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    std::string strInReserve = "";
    std::string strErrmsg = "";
    std::string strOutReserve = "";

    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    iRetCode = oCooperatorDaoStub4App.SetCooperatorPro(rCntlInfo, m_strMachineKey, m_strSource, m_dwSceneId,
                                ddwOption, oCooperatorProDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "oCooperatorDaoStub4App.SetCooperatorPro Failed "
                        "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(),
                        m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str());
    }

    return iRetCode;
}

int32_t CCooperatorAo::_SetCooperatorInfo(const CCntlInfo& rCntlInfo,
                                   uint64_t ddwOption,
                                   const b2b2c::cooperator::ddo::CCooperatorSetDdo oCooperatorSetDdo,
                                   c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    std::string strInReserve = "";
    std::string strErrmsg = "";
    std::string strOutReserve = "";

    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    iRetCode = oCooperatorDaoStub4App.SetCooperatorInfo(rCntlInfo, m_strMachineKey, m_strSource, m_dwSceneId,
                                ddwOption, oCooperatorSetDdo, strInReserve, strErrmsg, strOutReserve);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "oCooperatorDaoStub4App.SetCooperatorInfo Failed "
                        "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(),
                        m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str());
    }

    return iRetCode;
}

int32_t CCooperatorAo::_GetCooperatorBaseInfo4MsgQKeylog(const CCntlInfo& rCntlInfo,
                                const std::string& strMachineKey,
                                uint32_t dwSceneId,
                                const std::string& strSource,
                                uint8_t cFlag,
                                uint32_t dwCooperatorId,
                                b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
                                c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    uint32_t i = 0;
    std::string strInReserve;
    std::string strOutReserve;
    std::string strErrmsg;
    CCntlInfo oCntlInfo=rCntlInfo;
    std::stringstream oss;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());

    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo oCooperatorBaseInfoDdo;

    //调用DAO
    iRetCode = oCooperatorDaoStub4App.GetCooperatorBaseInfo(rCntlInfo, strMachineKey, strSource,
                        dwSceneId, dwCooperatorId, strInReserve, strErrmsg, oCooperatorBaseInfoDdo,
                        strOutReserve);
    oWTimeElf.AddTimeMark("GetCooperatorBaseInfo4MsgQKeylog", iRetCode, &m_oGetCooperatorBaseInfo4MsgQKeylog);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "GetCooperatorBaseInfo Failed "
                                "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                                m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),
                                dwSceneId, strErrmsg.c_str());
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    CCooperatorBaseInfoConv::Conv_CCooperatorBaseInfo_DdoToPo(oCooperatorBaseInfoDdo, oCooperatorBaseInfoPo);
    oCooperatorBaseInfoPo.DumpData(oss);

    //子帐号转化输出
    std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo> vecCooperatorSubAccountDdo = oCooperatorBaseInfoDdo.GetCooperatorSubAccountDdo();
    std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo> vecCooperatorSubAccountPo;
    for(i=0; i<vecCooperatorSubAccountDdo.size(); i++)
    {
        b2b2c::cooperator::po::CCooperatorSubAccountPo oCooperatorSubAccountPo;
        CCooperatorSubAccountConv::Conv_CCooperatorSubAccountDdoToPo(vecCooperatorSubAccountDdo[i], oCooperatorSubAccountPo);
        oCooperatorSubAccountPo.DumpData(oss);
        vecCooperatorSubAccountPo.push_back(oCooperatorSubAccountPo);
    }
    oCooperatorBaseInfoPo.SetCooperatorSubAccountPo(vecCooperatorSubAccountPo);

    if(KEY_LOG_START == cFlag) //开始log
    {
        C2C_WW_LOG_FKEY_PL35("ao_cooperator", 0, rCntlInfo, m_strSource, strIp, m_strMachineKey, C2C_KLOG_START, "@oCooperatorBaseInfoBefore=%s", oss.str().c_str());
    }else //结束log
    {
        C2C_WW_LOG_FKEY_PL35("ao_cooperator", 0, rCntlInfo, m_strSource, strIp, m_strMachineKey, C2C_KLOG_END, "@oCooperatorBaseInfoAfter=%s", oss.str().c_str());
    }

    C2C_WW_LOG("Call _GetCooperatorBaseInfo4MsgQKeylog Ok, CooperatorId:%u", dwCooperatorId);
    return iRetCode;
}

int32_t CCooperatorAo::_SendSendCooperatorBaseInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                uint32_t sceneId,
                                                uint32_t operatorId,
                                                uint32_t dwOperationType,
                                                std::set<uint32_t> setEventId,
                                                uint32_t eventLevel,
                                                const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPoBefore,
                                                const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPoAfter,
                                                c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    std::string strInReserve;
    std::string strErrmsg;
    CCntlInfo oCntlInfo=rCntlInfo;
    std::stringstream oss;
    std::stringstream ossOperatorId;
    b2b2c::cooperatorevent::ao::CCooperatorEventAoStub4App oCooperatorEventAoStub4App;

    //接口参数转换
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoBefore;
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoAfter;
    b2b2c::cooperatorevent::po::CCooperatorBaseInfoEventPo oCooperatorBaseInfoEventPoBefore;
    b2b2c::cooperatorevent::po::CCooperatorBaseInfoEventPo oCooperatorBaseInfoEventPoAfter;
    CCooperatorBaseInfoConv::Conv_CCooperatorBaseInfo_PoToEventPo(oCooperatorBaseInfoPoBefore, oCooperatorBaseInfoEventPoBefore);
    CCooperatorBaseInfoConv::Conv_CCooperatorBaseInfo_PoToEventPo(oCooperatorBaseInfoPoAfter, oCooperatorBaseInfoEventPoAfter);
    oCooperatorEventPoBefore.SetCooperatorBaseInfoEventPo(oCooperatorBaseInfoEventPoBefore);
    oCooperatorEventPoAfter.SetCooperatorBaseInfoEventPo(oCooperatorBaseInfoEventPoAfter);

    CAuthorizationField4App oCAuthorizationField4App;
    oCAuthorizationField4App.SetOperationType(dwOperationType);
    oCAuthorizationField4App.SetOperatorType(OPERATOR_COORPERATOR_BOSS);
    ossOperatorId << rCntlInfo.getOperatorUin();
    oCAuthorizationField4App.SetOperatorId(ossOperatorId.str());
    oCAuthorizationField4App.SetOperatorAuthType(BOSS_ID);
    oCAuthorizationField4App.SetOperatorAuthId(sceneId);

    //异步调用ao接口规范操作
    CCntlInfo& oCntlInfoSend = const_cast<CCntlInfo&>(oCntlInfo);
    oCntlInfoSend.setRouteKey(operatorId);
    IServiceControl* pSvcCntl = reinterpret_cast<IServiceControl*>(oCntlInfoSend.getCntl());
    pSvcCntl->NeedResp(false);
    iRetCode = oCooperatorEventAoStub4App.SendSendCooperatorEventMsgq(oCntlInfo, m_strMachineKey, __FILE__,
                                                        sceneId, 0, operatorId, setEventId,
                                                        eventLevel, oCooperatorEventPoBefore, oCooperatorEventPoAfter,
                                                        oCAuthorizationField4App, strInReserve);
    oWTimeElf.AddTimeMark("SendSendCooperatorBaseInfoEventMsgq", iRetCode, &m_oSendCooperatorBaseInfoEventMsgq);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "SendSendCooperatorEventMsgq error, OpUin:%u MachineKey:%s Source:%s SceneId:%u operatorId:%u eventLevel:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, operatorId, eventLevel, strErrmsg.c_str());
    }

    C2C_WW_LOG("Call _SendSendCooperatorBaseInfoEventMsgq Ok, operatorId:%u eventId:%u eventLevel%u",
                        operatorId, operatorId, eventLevel);
    return iRetCode;
}

int32_t CCooperatorAo::_GetCooperatorLicenseInfo4MsgQKeylog(
         const CCntlInfo& rCntlInfo,
         uint8_t cFlag,
         uint64_t ddwCooperatorId,
         std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePo,
         std::string& strOutReserve,
         c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    //读db
    int32_t iRetCode = 0;
    uint32_t i = 0;
    std::string strInReserve;
    std::string strErrmsg;
    std::stringstream oss;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    std::set<uint8_t> setLicenseType;

    b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
    std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo > vecCooperatorLicenseDdo;
    iRetCode = oCooperatorDaoStub4App.GetCooperatorLicense(rCntlInfo, m_strMachineKey, m_strSource,
                                    m_dwSceneId, ddwCooperatorId, setLicenseType, strInReserve, strErrmsg,
                                    vecCooperatorLicenseDdo, strOutReserve);
    oWTimeElf.AddTimeMark("GetCooperatorLicenseInfo4MsgQKeylog", iRetCode, &m_oGetCooperatorLicenseInfo4MsgQKeylog);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "GetCooperatorLicense Failed "
                                "OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s",
                                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),
                                m_dwSceneId, strErrmsg.c_str());
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
    }

    //输出数据转换
    for(i=0; i<(uint32_t)vecCooperatorLicenseDdo.size(); i++)
    {
        b2b2c::cooperator::po::CCooperatorLicensePo oCooperatorLicensePo;
        CCooperatorLicenseConv::Conv_CCooperatorLicense_DdoToPo(vecCooperatorLicenseDdo[i], oCooperatorLicensePo);
        oCooperatorLicensePo.DumpData(oss);
        vecCooperatorLicensePo.push_back(oCooperatorLicensePo);
    }

    if(KEY_LOG_START == cFlag) //开始log
    {
        C2C_WW_LOG_FKEY_PL35("ao_cooperator", 0, rCntlInfo, m_strSource, strIp, m_strMachineKey, C2C_KLOG_START, "@vecCooperatorLicensePoBefore=%s", oss.str().c_str());
    }else //结束log
    {
        C2C_WW_LOG_FKEY_PL35("ao_cooperator", 0, rCntlInfo, m_strSource, strIp, m_strMachineKey, C2C_KLOG_END, "@vecCooperatorLicensePoAfter=%s", oss.str().c_str());
    }

    C2C_WW_LOG("Call _GetCooperatorLicenseInfo4MsgQKeylog Ok, CooperatorId:%lu", ddwCooperatorId);
    return iRetCode;
}

int32_t CCooperatorAo::_SendSendCooperatorLicenseInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                        uint32_t sceneId,
                                                        uint32_t operatorId,
                                                        uint32_t dwOperationType,
                                                        std::set<uint32_t> setEventId,
                                                        uint32_t eventLevel,
                                                        const std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoBefore,
                                                        const std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoAfter,
                                                        c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    uint32_t i = 0;
    std::string strInReserve;
    std::string strErrmsg;
    CCntlInfo oCntlInfo=rCntlInfo;
    std::stringstream oss;
    std::stringstream ossOperatorId;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    b2b2c::cooperatorevent::ao::CCooperatorEventAoStub4App oCooperatorEventAoStub4App;

    //接口参数转换
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoBefore;
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoAfter;
    std::vector<b2b2c::cooperatorevent::po::CCooperatorLicenseEventPo > vecCooperatorLicenseEventPoBefore;
    std::vector<b2b2c::cooperatorevent::po::CCooperatorLicenseEventPo > vecCooperatorLicenseEventPoAfter;
    for(i=0; i< (uint32_t)vecCooperatorLicenseEventPoBefore.size(); i++)
    {
        b2b2c::cooperatorevent::po::CCooperatorLicenseEventPo oCooperatorLicenseEventPoBefore;
        CCooperatorLicenseConv::Conv_CCooperatorLicense_PoToEventPo(vecCooperatorLicenseEventPoBefore[i], oCooperatorLicenseEventPoBefore);
        vecCooperatorLicenseEventPoBefore.push_back(oCooperatorLicenseEventPoBefore);
    }
    for(i=0; i< (uint32_t)vecCooperatorLicenseEventPoAfter.size(); i++)
    {
        b2b2c::cooperatorevent::po::CCooperatorLicenseEventPo oCooperatorLicenseEventPoAfter;
        CCooperatorLicenseConv::Conv_CCooperatorLicense_PoToEventPo(vecCooperatorLicenseEventPoAfter[i], oCooperatorLicenseEventPoAfter);
        vecCooperatorLicenseEventPoAfter.push_back(oCooperatorLicenseEventPoAfter);
    }

    oCooperatorEventPoBefore.SetCooperatorLicenseEventPo(vecCooperatorLicenseEventPoBefore);
    oCooperatorEventPoAfter.SetCooperatorLicenseEventPo(vecCooperatorLicenseEventPoAfter);

    CAuthorizationField4App oCAuthorizationField4App;
    oCAuthorizationField4App.SetOperationType(dwOperationType);
    oCAuthorizationField4App.SetOperatorType(b2b2c::cooperator::OPERATOR_COORPERATOR_BOSS);
    operatorId = COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS;
    ossOperatorId << rCntlInfo.getOperatorUin();
    oCAuthorizationField4App.SetOperatorId(ossOperatorId.str());
    oCAuthorizationField4App.SetOperatorAuthType(BOSS_ID);
    oCAuthorizationField4App.SetOperatorAuthId(sceneId);

    //异步调用ao接口规范操作
    CCntlInfo& oCntlInfoSend = const_cast<CCntlInfo&>(oCntlInfo);

    oCntlInfoSend.setRouteKey(operatorId);

    IServiceControl* pSvcCntl = reinterpret_cast<IServiceControl*>(oCntlInfoSend.getCntl());
    pSvcCntl->NeedResp(false);
    iRetCode = oCooperatorEventAoStub4App.SendSendCooperatorEventMsgq(oCntlInfo, m_strMachineKey, __FILE__,
                                                        sceneId, 0, operatorId, setEventId,
                                                        eventLevel, oCooperatorEventPoBefore, oCooperatorEventPoAfter,
                                                        oCAuthorizationField4App, strInReserve);
    oWTimeElf.AddTimeMark("SendSendCooperatorLicenseInfoEventMsgq", iRetCode, &m_oSendCooperatorLicenseInfoEventMsgq);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "SendSendCooperatorEventMsgq error, OpUin:%u MachineKey:%s Source:%s SceneId:%u operatorId:%u eventLevel:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, operatorId, eventLevel, strErrmsg.c_str());
    }

    C2C_WW_LOG("Call _SendSendCooperatorLicenseInfoEventMsgq Ok, operatorId:%u eventId:%u eventLevel%u",
                        operatorId, operatorId, eventLevel);
    return iRetCode;
}

int32_t CCooperatorAo::_SendSendCooperatorSubAccountInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                        uint32_t sceneId,
                                                        uint32_t operatorId,
                                                        uint32_t dwOperationType,
                                                        std::set<uint32_t> setEventId,
                                                        uint32_t eventLevel,
                                                        const std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>& vecCooperatorSubAccountPoBefore,
                                                        const std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>& vecCooperatorSubAccountPoAfter,
                                                        c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    uint32_t i = 0;
    std::string strInReserve;
    std::string strErrmsg;
    CCntlInfo oCntlInfo=rCntlInfo;
    std::stringstream oss;
    std::stringstream ossOperatorId;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    b2b2c::cooperatorevent::ao::CCooperatorEventAoStub4App oCooperatorEventAoStub4App;

    //接口参数转换
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoBefore;
    b2b2c::cooperatorevent::po::CCooperatorEventPo oCooperatorEventPoAfter;
    std::vector<b2b2c::cooperatorevent::po::CCooperatorSubAccountEventPo > vecCooperatorSubAccountEventPoBefore;
    std::vector<b2b2c::cooperatorevent::po::CCooperatorSubAccountEventPo > vecCooperatorSubAccountEventPoAfter;
    for(i=0; i< (uint32_t)vecCooperatorSubAccountPoBefore.size(); i++)
    {
        b2b2c::cooperatorevent::po::CCooperatorSubAccountEventPo oCooperatorSubAccountEventPoBefore;
        CCooperatorSubAccountConv::Conv_CCooperatorSubAccountPoToEventPo(vecCooperatorSubAccountPoBefore[i],
                oCooperatorSubAccountEventPoBefore);
        vecCooperatorSubAccountEventPoBefore.push_back(oCooperatorSubAccountEventPoBefore);
    }
    for(i=0; i< (uint32_t)vecCooperatorSubAccountPoAfter.size(); i++)
    {
        b2b2c::cooperatorevent::po::CCooperatorSubAccountEventPo oCooperatorSubAccountEventPoAfter;
        CCooperatorSubAccountConv::Conv_CCooperatorSubAccountPoToEventPo(vecCooperatorSubAccountPoAfter[i],
                oCooperatorSubAccountEventPoAfter);
        vecCooperatorSubAccountEventPoAfter.push_back(oCooperatorSubAccountEventPoAfter);
    }

    oCooperatorEventPoBefore.SetCooperatorSubAccountEventPo(vecCooperatorSubAccountEventPoBefore);
    oCooperatorEventPoAfter.SetCooperatorSubAccountEventPo(vecCooperatorSubAccountEventPoAfter);

    CAuthorizationField4App oCAuthorizationField4App;
    oCAuthorizationField4App.SetOperationType(dwOperationType);
    oCAuthorizationField4App.SetOperatorType(b2b2c::cooperator::OPERATOR_COORPERATOR_BOSS);
    operatorId = COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS;
    ossOperatorId << rCntlInfo.getOperatorUin();
    oCAuthorizationField4App.SetOperatorId(ossOperatorId.str());
    oCAuthorizationField4App.SetOperatorAuthType(BOSS_ID);
    oCAuthorizationField4App.SetOperatorAuthId(sceneId);

    //异步调用ao接口规范操作
    CCntlInfo& oCntlInfoSend = const_cast<CCntlInfo&>(oCntlInfo);

    oCntlInfoSend.setRouteKey(operatorId);

    IServiceControl* pSvcCntl = reinterpret_cast<IServiceControl*>(oCntlInfoSend.getCntl());
    pSvcCntl->NeedResp(false);
    iRetCode = oCooperatorEventAoStub4App.SendSendCooperatorEventMsgq(oCntlInfo, m_strMachineKey, __FILE__,
                                                        sceneId, 0, operatorId, setEventId,
                                                        eventLevel, oCooperatorEventPoBefore, oCooperatorEventPoAfter,
                                                        oCAuthorizationField4App, strInReserve);
    oWTimeElf.AddTimeMark("SendCooperatorSubAccountInfoEventMsgq", iRetCode, &m_oSendCooperatorSubAccountInfoEventMsgq);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "SendSendCooperatorEventMsgq error, OpUin:%u MachineKey:%s Source:%s SceneId:%u operatorId:%u eventLevel:%u ErrMsg:%s",
                        m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, operatorId, eventLevel, strErrmsg.c_str());
    }

    C2C_WW_LOG("Call _SendSendCooperatorSubAccountInfoEventMsgq Ok, operatorId:%u eventId:%u eventLevel%u",
                        operatorId, operatorId, eventLevel);
    return iRetCode;
}

void CCooperatorAo::_GetCooperatorLicenseInfoMsgQSetEventId(
            std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoBefore,
            std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoAfter,
            std::set<uint32_t>& setEventId)
{
    std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>::iterator itLicensePoBefore;
    std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>::iterator itLicensePoAfter;
    for(itLicensePoAfter=vecCooperatorLicensePoAfter.begin();
            itLicensePoAfter!=vecCooperatorLicensePoAfter.end(); itLicensePoAfter++)
    {
        itLicensePoBefore = findLicense(vecCooperatorLicensePoBefore.begin(),
                vecCooperatorLicensePoBefore.end(), (*itLicensePoAfter));
        if( itLicensePoBefore == vecCooperatorLicensePoBefore.end())
        {
            //没有找到，新增的子帐号
            setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_ADD);
        }else
        {
            //判断许可证信息是否有发生变化
            if( (*itLicensePoAfter).GetLicenseCode() != (*itLicensePoBefore).GetLicenseCode())
            {
                setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_MODITY);
                if( setEventId.size() == 2 )
                {
                    break;
                }
                continue;
            }

            if( (*itLicensePoAfter).GetCooperatorScope() != (*itLicensePoBefore).GetCooperatorScope())
            {
                setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_MODITY);
                if( setEventId.size() == 2 )
                {
                    break;
                }
                continue;
            }

            if( (*itLicensePoAfter).GetLicenseBeginDate() != (*itLicensePoBefore).GetLicenseBeginDate())
            {
                setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_MODITY);
                if( setEventId.size() == 2 )
                {
                    break;
                }
                continue;
            }

            if( (*itLicensePoAfter).GetLicenseEndDate() != (*itLicensePoBefore).GetLicenseEndDate())
            {
                setEventId.insert(COOPERATOR_EVENT_ID_LICENSE_MODITY);
                if( setEventId.size() == 2 )
                {
                    break;
                }
                continue;
            }
        }
    }
}

int32_t CCooperatorAo::_GetNode(const CCntlInfo& rCntlInfo,
        uint32_t dwNodeId, //品类或者一级类目ID
        b2b2c::nca::ddo::CNavDdo& navDdo,
        c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf)
{
    int32_t iRetCode = 0;
    std::string strInReserve = "";
    std::string strErrmsg = "";
    std::string strOutReserve = "";

    C2C_WW_SIM_LOG_PL_HEAD();

    b2b2c::nca::dao::CNcaDaoStub4App oCNcaDaoStub4App;
    iRetCode = oCNcaDaoStub4App.GetNav_WG(rCntlInfo, m_strMachineKey,
                                m_strSource, m_dwSceneId, 1, dwNodeId, strInReserve,
                                strErrmsg, navDdo, strOutReserve);
    oWTimeElf.AddTimeMark("oCNcaDaoStub4App.GetNav", iRetCode, &m_oGetNode);
    if(iRetCode != 0)
    {
        C2C_WW_LOG_ERR(iRetCode, "oCNcaDaoStub4App.GetNav Failed "
                                "OpUin:%u MachineKey:%s Source:%s SceneId:%u nodeId:%u ErrMsg:%s",
                                m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwNodeId, strErrmsg.c_str());
        return iRetCode;
    }

    C2C_WW_LOG("Call _GetNode ok, nodeId:%u nodeName:%s", dwNodeId, navDdo.GetNavNode().GetName().c_str());
    return iRetCode;
}

/**
 *
 * 从管理后台等其他业务同步过来的设置合作伙伴属性位等信息的接口
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint64_t option: 选项,暂未用  [in]
 *@param CooperatorSetPo cooperatorSetPo: 合作伙伴属性位设置，包括合作伙伴ID、设置和取消属性值设置的参数（设置和取消的属性位不能冲突）等，必填  [in]
 *@param String inReserve: 请求保留字  [in]
 *@param String errmsg: 错误信息    [out]
 *@param CooperatorBaseInfoPo cooperatorBaseInfoPo: 设置合作伙伴信息成功后，返回合作伙伴全部的基本信息   [out]
 *@param String outReserve: 输出保留字   [out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::SetCooperatorInfo(
                const CCntlInfo& rCntlInfo,
                const std::string& strMachineKey,
                const std::string& strSource,
                uint32_t dwSceneId,
                uint64_t ddwOption,
                const b2b2c::cooperator::po::CCooperatorSetPo& oCooperatorSetPo,
                const std::string& strInReserve,
                std::string& strErrmsg,
                b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
                std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    std::stringstream oss;
    oCooperatorSetPo.DumpData(oss);
    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorSetPo:%s",
            __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, oss.str().c_str());
    C2C_WW_SIM_LOG_PL_HEAD();
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oSetCooperatorInfo);

    std::set<uint32_t> setEventId;
    std::string strIp;
    strIp = IpToString(rCntlInfo.getOperatorClientIP());
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    m_dwSceneId=dwSceneId;
    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    uint32_t dwCooperatorId = 0;

    iRetCode=_CheckRequest();
    if(iRetCode)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    b2b2c::cooperator::ddo::CCooperatorSetDdo oCooperatorSetDdo;
    if(oCooperatorSetPo.IsCooperatorProPoSet()){
        dwCooperatorId = oCooperatorSetPo.GetCooperatorProPo().GetCooperatorId();
        iRetCode = _ParameterCheckCooperatorProPo(oCooperatorSetPo.GetCooperatorProPo());
        if(iRetCode){
            C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
            return iRetCode;
        }

        b2b2c::cooperator::ddo::CCooperatorProDdo oCooperatorProDdo;
        CCooperatorBaseInfoConv::Conv_CCooperatorPro_PoToDdo(oCooperatorSetPo.GetCooperatorProPo(), oCooperatorProDdo); //合作伙伴属性位po转换
        oCooperatorSetDdo.SetCooperatorProDdo(oCooperatorProDdo);
    }
    if(oCooperatorSetPo.IsCooperatorSubProPoSet()){
        dwCooperatorId = oCooperatorSetPo.GetCooperatorSubProPo().GetCooperatorId();
        iRetCode = _ParameterCheckCooperatorSubProPo(oCooperatorSetPo.GetCooperatorSubProPo());
        if(iRetCode){
            C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
            return iRetCode;
        }
        b2b2c::cooperator::ddo::CCooperatorSubProDdo oCooperatorSubProDdo;
        CCooperatorBaseInfoConv::Conv_CCooperatorPro_PoToDdo(oCooperatorSetPo.GetCooperatorSubProPo(), oCooperatorSubProDdo); //合作伙伴子帐号属性位po转换
        oCooperatorSetDdo.SetCooperatorSubProDdo(oCooperatorSubProDdo);
    }

    b2b2c::cooperator::po::CCooperatorBaseInfoPo oCooperatorBaseInfoPoBefore;

    //更新合作伙伴信息前记录keylog
    uint32_t dwRet = _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_START, dwCooperatorId,
                                                        oCooperatorBaseInfoPoBefore, oWTimeElf);
    if(dwRet){
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    iRetCode =  _SetCooperatorInfo(rCntlInfo, ddwOption, oCooperatorSetDdo, oWTimeElf);
    if(iRetCode!=0)
    {
        C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
        return iRetCode;
    }

    //更新合作伙伴信息成功后，记录keylog
    _GetCooperatorBaseInfo4MsgQKeylog(rCntlInfo, strMachineKey, dwSceneId, __FILE__, KEY_LOG_END, dwCooperatorId,
                                        oCooperatorBaseInfoPo, oWTimeElf);

    //发送msgq通知
    setEventId.insert(COOPERATOR_EVENT_ID_BASEINFO_MODITY);
    _SendSendCooperatorBaseInfoEventMsgq(rCntlInfo, m_dwSceneId, COOPERATOR_EVENT_OPERATORID_COOPERATOR4BOSS, OP_MODIFY, setEventId, 0,
                                            oCooperatorBaseInfoPoBefore, oCooperatorBaseInfoPo, oWTimeElf);

    C2C_WW_LOG("%s Finished OpUin:%u MachineKey:%s Source:%s SceneId:%u CooperatorProPo:%s",
                    __FUNCTION__, m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId, oss.str().c_str());
    return 0;
}

/**
 *
 * 获取价格告警模版列表
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param Vector CooperatorMonitorModelPo: 告警模版列表 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorMonitorModelList(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelPo >& vecCooperatorMonitorModelPo,
				std::string& strRulesruleJson,
				std::string& strOutReserve
	)
{

	strRulesruleJson = m_monitorRuleJson;//规则字符串赋值

	int32_t iRetCode = 0;

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	uint32_t dwCacheExpireTime = 0;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetMonitorModelListGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u dwCooperatorId:%u",
			__FUNCTION__,m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwCooperatorId);

	//基本参数校验
	iRetCode=_CheckRequest();
	if(iRetCode!=0)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//返回的ddolist
	std::vector<b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo > vecCooperatorMonitorModelDdo;
	//从cache中取ddoList
	//Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_REQ,1);

	std::stringstream ssKey;
	ssKey << COOPERATOR_MONITOR_CMEM_PREFIX;
	ssKey << dwCooperatorId;
	iRetCode = TMEM_CACHE_OP->GetSimpleData(ssKey.str(), vecCooperatorMonitorModelDdo, dwCacheExpireTime);
	oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->GetSimpleData", iRetCode, &m_oGetDataFromTmemGroup);

	//没有数据
	if(0!=iRetCode || vecCooperatorMonitorModelDdo.empty()){
		//没有取到数据调用DAO
		//Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_ERR,1);

		b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
		iRetCode = oCooperatorDaoStub4App.GetCooperatorMonitorModelList(rCntlInfo, strMachineKey, strSource,
							dwSceneId, dwCooperatorId, strInReserve, strErrmsg, vecCooperatorMonitorModelDdo,
							strOutReserve);

		oWTimeElf.AddTimeMark( "oCooperatorDaoStub4App->GetCooperatorMonitorModelList", iRetCode);

		//未取到数据
		if(0!=iRetCode)
		{
			if(iRetCode==ERR_B2B2C_DBSTORAGE_ITEM_NOT_EXIT){
				//如果返回数据为空 则插入一条系统规则模版
				b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo oCooperatorMonitorModelDdo;

				//申请一个id
				uint32_t dwModelId = IDMAKER_HANDLER->GetNeedIdForU32(rCntlInfo,COOPERATOR_MONITOR_IDMAKER_TYPE);
				if(dwModelId==0){
					iRetCode=ERR_MONITORMODEL_IDMAKER_GET;
					C2C_WW_LOG_ERR(iRetCode,"IDMAKER_HANDLER.GetNeedIdForU32 faild.ErrMsg:(%s)",IDMAKER_HANDLER->GetLastErrMsg());
					C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
					return iRetCode;
				}

				oWTimeElf.AddTimeMark( "IDMAKER_HANDLER->GetNeedIdForU32", iRetCode);

				//设置模版信息
				oCooperatorMonitorModelDdo.SetModelId(dwModelId);
				oCooperatorMonitorModelDdo.SetCooperatorId(dwCooperatorId);
				oCooperatorMonitorModelDdo.SetModelName("系统模版");
				oCooperatorMonitorModelDdo.SetModelRule("");//系统规则，空的，代码中重新赋值
				oCooperatorMonitorModelDdo.SetModelState(MONITOR_MODEL_TYPE_SYS);//模版状态 默认关闭
				oCooperatorMonitorModelDdo.SetMonitorTouch(MONITOR_MODEL_TOUCH_TYPE_NULL);//触达类型默认全关
				oCooperatorMonitorModelDdo.SetModelType(MONITOR_MODEL_STATE_OFF);//系统模版类

				//调用DAO插入系统模版
				iRetCode = oCooperatorDaoStub4App.UpdateCooperatorMonitorModel(rCntlInfo, strMachineKey, strSource,
						dwSceneId,oCooperatorMonitorModelDdo,strInReserve,strErrmsg,strOutReserve);

				oWTimeElf.AddTimeMark( "oCooperatorDaoStub4App->UpdateCooperatorMonitorModel", iRetCode);
				//插入失败
				if(0!=iRetCode)
				{
					C2C_WW_LOG_ERR(iRetCode, "UpdateCooperatorMonitorModel Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s dwCooperatorId:%u",
											m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str(),dwCooperatorId);
					C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
					return iRetCode;
				}

				//加入数组中
				vecCooperatorMonitorModelDdo.push_back(oCooperatorMonitorModelDdo);
			}else{
				C2C_WW_LOG_ERR(iRetCode, "GetCooperatorMonitorModelList Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s dwCooperatorId:%u",
										m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str(),dwCooperatorId);
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			}

		}
	}


	//oWTimeElf.AddTimeMark( "Start Parse Rule", iRetCode);

	std::vector<b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo >::iterator itDdo = vecCooperatorMonitorModelDdo.begin();
	for(;itDdo != vecCooperatorMonitorModelDdo.end();itDdo++)
	{
		if(itDdo->GetModelType() == MONITOR_MODEL_TYPE_SYS)
		{
			itDdo->SetModelRule(m_monitorSysRule);
		}

		b2b2c::cooperator::po::CCooperatorMonitorModelPo oCooperatorMonitorModelPo;
		oCooperatorMonitorModelPo.SetModelId(itDdo->GetModelId());
		oCooperatorMonitorModelPo.SetCooperatorId(itDdo->GetCooperatorId());
		oCooperatorMonitorModelPo.SetModelName(itDdo->GetModelName());
		oCooperatorMonitorModelPo.SetModelState(itDdo->GetModelState());
		oCooperatorMonitorModelPo.SetModelType(itDdo->GetModelType());
		oCooperatorMonitorModelPo.SetMonitorTouch(itDdo->GetMonitorTouch());
		oCooperatorMonitorModelPo.SetModelLastUpdateTime(itDdo->GetModelLastUpdateTime());
		oCooperatorMonitorModelPo.SetModelAddTime(itDdo->GetModelAddTime());

		//规则转换
		std::string & strModelRule = itDdo->GetModelRule();
		if(!strModelRule.empty()){
			//规则转换成json
			Json::Reader reader;
			Json::Value ruleList;
			//转换成功且长度不为0
			if (reader.parse(strModelRule, ruleList, false) && !ruleList.empty())
			{
				for(Json::Value::iterator itr=ruleList.begin();itr!=ruleList.end();itr++)
				{
					//有内容
					if(!(*itr).empty())
					{
						std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelRulePo> vecCMMRulePo;
						for(Json::Value::iterator iter=(*itr).begin();iter!=(*itr).end();iter++)
						{
							if((*iter).isMember("mo")&&(*iter).isMember("co")&&(*iter).isMember("cm")&&(*iter).isMember("cv"))
							{
								uint32_t dwMoval = (*iter)["mo"].asInt();
								uint32_t dwCoval = (*iter)["co"].asInt();
								uint32_t dwCmval = (*iter)["cm"].asInt();
								uint32_t dwCvval = (*iter)["cv"].asInt();

								//检验是否合法
								std::stringstream strMapkey;
								strMapkey<<dwMoval<<":"<<dwCoval<<":"<<dwCmval;

								//是否在规则map中
								std::map<std::string,Json::Value>::iterator itRuleMap;
								itRuleMap = m_monitorRuleMap.find(strMapkey.str());
								//有找到
								if(itRuleMap!=m_monitorRuleMap.end())
								{
									//继续校验
									Json::Value validInfo = itRuleMap->second;
									uint32_t dwCvMin = validInfo["min"].asInt();//值范围
									uint32_t dwCvMax = validInfo["max"].asInt();//值范围
									std::string strRuleMsg = validInfo["msg"].asString();//规则告警描述
									std::string strCmDesc = validInfo["desc"].asString();//规则算法描述
									//范围校验
									if(dwCvval >dwCvMin && dwCvval <=dwCvMax){
										b2b2c::cooperator::po::CCooperatorMonitorModelRulePo oCMMRulePo;
										oCMMRulePo.SetMo(dwMoval);
										oCMMRulePo.SetCo(dwCoval);
										oCMMRulePo.SetCm(dwCmval);
										oCMMRulePo.SetCv(dwCvval);
										oCMMRulePo.SetMsg(strRuleMsg);
										oCMMRulePo.SetCmDesc(strCmDesc);

										//加入规则Po列表中
										vecCMMRulePo.push_back(oCMMRulePo);
									}
								}
							}
						}
						//放入po的规则对象中
						if(!vecCMMRulePo.empty())
						{
							oCooperatorMonitorModelPo.GetModelRule().push_back(vecCMMRulePo);
						}
					}
				}
			}
		}

		vecCooperatorMonitorModelPo.push_back(oCooperatorMonitorModelPo);
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  CooperatorId:%u", __FUNCTION__,
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwCooperatorId);

	//成功
	iRetCode=0;

	return iRetCode;
}

/**
 *
 * 通过模版ID获取告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param CooperatorMonitorModelPo CooperatorMonitorModelPo: 告警模版 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u dwCooperatorId:%u dwModelId:%u",
			__FUNCTION__,m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,dwCooperatorId,dwModelId);

	//基本参数校验
	iRetCode=_CheckRequest();
	if(iRetCode!=0)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//获取列表然后筛选的办法
	std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelPo > vecCooperatorMonitorModelPo;
	std::string strRulesRuleJson;
	iRetCode = GetCooperatorMonitorModelList(
			rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwCooperatorId,
			strInReserve,
			strErrmsg,
			vecCooperatorMonitorModelPo,
			strRulesRuleJson,
			strOutReserve
	);
	//获取失败了 直接返回
	if(0!=iRetCode)
	{
		return iRetCode;
	}

	iRetCode = ERR_MONITORMODEL_GETBYID_CANNOTFIND;
	//遍历vector找到modelid相同的po
	for(uint32_t i=0;i<vecCooperatorMonitorModelPo.size();i++)
	{
		if(vecCooperatorMonitorModelPo[i].GetModelId()==dwModelId)
		{
			oCooperatorMonitorModelPo = vecCooperatorMonitorModelPo[i];
			iRetCode=0;
			break;
		}
	}

	//没找到
	if(0!=iRetCode)
	{
		C2C_WW_LOG_ERR(iRetCode,"can not find modelid:%u from modelPolist",dwModelId);
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  CooperatorId:%u ModelId:%u", __FUNCTION__,
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwCooperatorId,dwModelId);

	return iRetCode;
}


int32_t CCooperatorAo::_GetModelRuleInfo(
		   const b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
		   std::string& strModelRule
	)
{
	int32_t iRetCode = 0;
	//拼规则和校验规则
	const std::vector<std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelRulePo> > & vecVecCMMRulePo = oCooperatorMonitorModelPo.GetModelRule();
	Json::Value ruleList;
	for(uint32_t i=0;i<vecVecCMMRulePo.size();i++)
	{
		const std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelRulePo> & vecCMMRulePo = vecVecCMMRulePo[i];
		Json::Value ruleUnit;//数组
		for(uint32_t j=0;j<vecCMMRulePo.size();j++)
		{
			const b2b2c::cooperator::po::CCooperatorMonitorModelRulePo & oCmmRulePo = vecCMMRulePo[j];
			//校验参数
			uint32_t dwMoval = oCmmRulePo.GetMo();
			uint32_t dwCoval = oCmmRulePo.GetCo();
			uint32_t dwCmval = oCmmRulePo.GetCm();
			uint32_t dwCvval = oCmmRulePo.GetCv();

			//检验是否合法
			std::stringstream strMapkey;
			strMapkey<<dwMoval<<":"<<dwCoval<<":"<<dwCmval;

			//是否在规则map中
			std::map<std::string,Json::Value>::iterator itRuleMap;
			itRuleMap = m_monitorRuleMap.find(strMapkey.str());
			//有找到
			if(itRuleMap!=m_monitorRuleMap.end())
			{
				//继续校验
				Json::Value validInfo = itRuleMap->second;
				uint32_t dwCvMin = validInfo["min"].asInt();//值范围
				uint32_t dwCvMax = validInfo["max"].asInt();//值范围
				//范围校验
				if(dwCvval >dwCvMin && dwCvval <=dwCvMax)
				{
					//构造json对象
					Json::Value ruleItem;
					ruleItem["mo"]= dwMoval;
					ruleItem["co"]= dwCoval;
					ruleItem["cm"]= dwCmval;
					ruleItem["cv"]= dwCvval;
					ruleUnit.append(ruleItem);
				}
				else
				{
					iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
					//报错
					C2C_WW_LOG_ERR(iRetCode, "Invalid date cv overflow MonitorModelRule[%u,%u] {mo:%u,co:%u,cm:%u,cv:%u}, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
							i,j,dwMoval,dwCoval,dwCmval,dwCvval, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
					return iRetCode;
				}
			}
			else
			{
				//报错 直接退出
				//报错
				iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
				C2C_WW_LOG_ERR(iRetCode, "Invalid date can not find out MonitorModelRule[%u,%u] {mo:%u,co:%u,cm:%u,cv:%u}, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
						i,j,dwMoval,dwCoval,dwCmval,dwCvval, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
				return iRetCode;
			}
		}
		ruleList.append(ruleUnit);
	}

	Json::FastWriter writer;
	//没有值
	if(!ruleList.empty())
	{
		strModelRule = writer.write(ruleList);
		//最小结构
		//[[{"mo":1,"co":1,"cm":1,"cv":1}]]
		if(strModelRule.length() < MONITOR_MIN_MODEL_RULE_LENGTH || strModelRule.length() > MONITOR_MAX_MODEL_RULE_LENGTH)
		{
			iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
			//长度不正确 报错
			C2C_WW_LOG_ERR(iRetCode, "Invalid date parsed rule:%s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
					strModelRule.c_str(), m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
			return iRetCode;
		}
	}
	else
	{
		strModelRule = "";
	}

	return iRetCode;
}


/**
 *
 * 新增或者更新告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param CooperatorMonitorModelPo CooperatorMonitorModelPo: 告警模版，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::UpdateCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;


	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oUpdateMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u",
			__FUNCTION__,m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId);


	//oWTimeElf.AddTimeMark( "Validate Start", iRetCode);
	//基本参数校验
	iRetCode=_CheckRequest();
	if(iRetCode!=0)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//校验cooperatorId，无论新增或者更新都必填
	if(!oCooperatorMonitorModelPo.IsCooperatorIdSet() || oCooperatorMonitorModelPo.GetCooperatorId()<10000)
	{
		iRetCode=ERR_MONITORMODEL_UPDATE_NOID;
		//错误数据 报错返回
		C2C_WW_LOG_ERR(iRetCode, "cooperatorId not set, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//判断新增还是更新
	//更新的ddo对象
	b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo oCooperatorMonitorModelDdo;
	uint32_t dwCooperatorId = oCooperatorMonitorModelPo.GetCooperatorId();
	uint32_t dwModelId=oCooperatorMonitorModelPo.GetModelId();
	if(oCooperatorMonitorModelPo.IsModelIdSet())
	{
		if(0 != dwModelId)//有值
		{
			b2b2c::cooperator::po::CCooperatorMonitorModelPo oldModelPo;
			iRetCode = GetCooperatorMonitorModel(
					rCntlInfo,
					strMachineKey,
					strSource,
					dwSceneId,
					dwCooperatorId,
					dwModelId,
					strInReserve,
					strErrmsg,
					oldModelPo,
					strOutReserve
			);

			//不存在这个modelid 直接返回
			if(0!=iRetCode)
			{
				return iRetCode;
			}

			if(MONITOR_MODEL_TYPE_SYS != oldModelPo.GetModelType())
			{
				//自定义模版，检查更新ModelName,MonitorTouch,ModelState,ModelRule
				if(oCooperatorMonitorModelPo.IsModelNameSet() ||
				   oCooperatorMonitorModelPo.IsMonitorTouchSet() ||
				   oCooperatorMonitorModelPo.IsModelStateSet() ||
				   oCooperatorMonitorModelPo.IsModelRuleSet())
				{
					//模版名称存在进行校验
					if(oCooperatorMonitorModelPo.IsModelNameSet())
					{
						const std::string & strModelName = oCooperatorMonitorModelPo.GetModelName();
						if(strModelName.length() > MONITOR_MAX_MODEL_NAME_LENGTH || strModelName.empty())
						{
							iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
							C2C_WW_LOG_ERR(iRetCode, "Invalid date modelName:%s, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
									strModelName.c_str(), m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetModelName(strModelName);
					}

					//模版触达方式存在进行校验
					if(oCooperatorMonitorModelPo.IsMonitorTouchSet())
					{
						uint16_t wMonitorTouch = oCooperatorMonitorModelPo.GetMonitorTouch();
						if(wMonitorTouch > MONITOR_MODEL_TOUCH_TYPE_MSG_MAIL_TIPS){
							iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
							C2C_WW_LOG_ERR(iRetCode, "Invalid date monitorTouch:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
									wMonitorTouch, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetMonitorTouch(wMonitorTouch);
					}

					//模版状态存在进行校验
					if(oCooperatorMonitorModelPo.IsModelStateSet())
					{
						uint16_t wModelState = oCooperatorMonitorModelPo.GetModelState();
						if(wModelState > MONITOR_MODEL_STATE_ON){
							iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
							C2C_WW_LOG_ERR(iRetCode, "Invalid date modelState:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
									wModelState, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetModelState(wModelState);
					}

					//告警模版内容
					if(oCooperatorMonitorModelPo.IsModelRuleSet())
					{
						std::string strModelRule;
						iRetCode = _GetModelRuleInfo(oCooperatorMonitorModelPo,strModelRule);
						if(0!=iRetCode)
						{
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetModelRule(strModelRule);
					}

				}
				else
				{
					//报错
					iRetCode=ERR_MONITORMODEL_UPDATE_NODATA;
					C2C_WW_LOG_ERR(iRetCode, "no data for update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
							m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
					C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
					return iRetCode;
				}
			}
			else
			{
				//系统模版，检查更新MonitorTouch,ModelState
				if(oCooperatorMonitorModelPo.IsMonitorTouchSet() || oCooperatorMonitorModelPo.IsModelStateSet())
				{
					//参数判断
					//模版触达方式存在进行校验
					if(oCooperatorMonitorModelPo.IsMonitorTouchSet())
					{
						uint16_t wMonitorTouch = oCooperatorMonitorModelPo.GetMonitorTouch();
						if(wMonitorTouch > MONITOR_MODEL_TOUCH_TYPE_MSG_MAIL_TIPS){
							iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
							C2C_WW_LOG_ERR(iRetCode, "Invalid date monitorTouch:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
									wMonitorTouch, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetMonitorTouch(wMonitorTouch);
					}

					//模版状态存在进行校验
					if(oCooperatorMonitorModelPo.IsModelStateSet())
					{
						uint16_t wModelState = oCooperatorMonitorModelPo.GetModelState();
						if(wModelState > MONITOR_MODEL_STATE_ON){
							iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
							C2C_WW_LOG_ERR(iRetCode, "Invalid date modelState:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
									wModelState, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
							C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
							return iRetCode;
						}
						oCooperatorMonitorModelDdo.SetModelState(wModelState);
					}
				}
				else
				{
					//报错
					iRetCode=ERR_MONITORMODEL_UPDATE_NODATA;
					C2C_WW_LOG_ERR(iRetCode, "no data for update, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
							m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
					C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
					return iRetCode;
				}
			}
		}
		else
		{
			iRetCode=ERR_MONITORMODEL_UPDATE_NOID;
			//错误数据 报错返回
			C2C_WW_LOG_ERR(iRetCode, "modelid for update is zero, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
			C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
			return iRetCode;
		}
	}
	else
	{
		//进入新增流程
		//先进行参数校验
		//新增中除了modelRule可以不填，modelName,modelState,monitorTouch要必填
		if(oCooperatorMonitorModelPo.IsModelNameSet() &&
		   oCooperatorMonitorModelPo.IsMonitorTouchSet() &&
		   oCooperatorMonitorModelPo.IsModelStateSet())
		{
			//参数校验
			const std::string & strModelName = oCooperatorMonitorModelPo.GetModelName();
			if(strModelName.length() > MONITOR_MAX_MODEL_NAME_LENGTH || strModelName.empty())
			{
				iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
				C2C_WW_LOG_ERR(iRetCode, "Invalid date modelName:%s, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
						strModelName.c_str(), m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			}


			uint16_t wMonitorTouch = oCooperatorMonitorModelPo.GetMonitorTouch();
			if(wMonitorTouch > MONITOR_MODEL_TOUCH_TYPE_MSG_MAIL_TIPS){
				iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
				C2C_WW_LOG_ERR(iRetCode, "Invalid date monitorTouch:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
						wMonitorTouch, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			}


			uint16_t wModelState = oCooperatorMonitorModelPo.GetModelState();
			if(wModelState > MONITOR_MODEL_STATE_ON){
				iRetCode=ERR_MONITORMODEL_UPDATE_INVALID;
				C2C_WW_LOG_ERR(iRetCode, "Invalid date modelState:%u, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
						wModelState, m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			}

			//设置OK
			oCooperatorMonitorModelDdo.SetModelName(strModelName);
			oCooperatorMonitorModelDdo.SetMonitorTouch(wMonitorTouch);
			oCooperatorMonitorModelDdo.SetModelState(wModelState);
		}
		else
		{
			iRetCode=ERR_MONITORMODEL_UPDATE_NODATA;
			C2C_WW_LOG_ERR(iRetCode, "Incomplete data for insert, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
			C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
			return iRetCode;
		}

		if(oCooperatorMonitorModelPo.IsModelRuleSet())
		{
			std::string strModelRule;
			iRetCode = _GetModelRuleInfo(oCooperatorMonitorModelPo,strModelRule);
			if(0!=iRetCode)
			{
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			}
			oCooperatorMonitorModelDdo.SetModelRule(strModelRule);
		}
		//如果不设置，默认就是空串


		//获取列表数据
		//新增时用于验证是否超过数量限制
		std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelPo > vecCooperatorMonitorModelPo;
		std::string rulesRuleJson;
		iRetCode = GetCooperatorMonitorModelList(
				rCntlInfo,
				strMachineKey,
				strSource,
				dwSceneId,
				dwCooperatorId,
				strInReserve,
				strErrmsg,
				vecCooperatorMonitorModelPo,
				rulesRuleJson,
				strOutReserve
		);
		//获取失败了 直接返回
		if(0!=iRetCode)
		{
			return iRetCode;
		}
		//先判断是否超过总数限制 4条规则
		if(vecCooperatorMonitorModelPo.size() >= MONITOR_MAX_MODEL_COUNT_LIMIT)
		{
			iRetCode=ERR_MONITORMODEL_INSERT_LIMIT;
			C2C_WW_LOG_ERR(iRetCode, "Limit of Model Count OpUin:%u MachineKey:%s Source:%s SceneId:%u",
					m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
			C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
			return iRetCode;
		}

		dwModelId = IDMAKER_HANDLER->GetNeedIdForU32(rCntlInfo,COOPERATOR_MONITOR_IDMAKER_TYPE);
		if(dwModelId==0){
			iRetCode=ERR_MONITORMODEL_IDMAKER_GET;
			C2C_WW_LOG_ERR(iRetCode,"IDMAKER_HANDLER.GetNeedIdForU32 faild.ErrMsg:(%s)",IDMAKER_HANDLER->GetLastErrMsg());
			C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
			return iRetCode;
		}
		oWTimeElf.AddTimeMark( "IDMAKER_HANDLER->GetNeedIdForU32", iRetCode);


		//这个入口只能新增自定义模版
		//默认设置type=1
		oCooperatorMonitorModelDdo.SetModelType(MONITOR_MODEL_TYPE_USER);
	}


	oCooperatorMonitorModelDdo.SetCooperatorId(dwCooperatorId);
	oCooperatorMonitorModelDdo.SetModelId(dwModelId);

	b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;
	//调用DAO插入系统模版
	iRetCode = oCooperatorDaoStub4App.UpdateCooperatorMonitorModel(rCntlInfo, strMachineKey, strSource,
			dwSceneId,oCooperatorMonitorModelDdo,strInReserve,strErrmsg,strOutReserve);

	oWTimeElf.AddTimeMark( "oCooperatorDaoStub4App->UpdateCooperatorMonitorModel", iRetCode);
	//插入失败
	if(0!=iRetCode)
	{
		C2C_WW_LOG_ERR(iRetCode, "UpdateCooperatorMonitorModel Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s dwCooperatorId:%u",
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str(),dwCooperatorId);
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  CooperatorId:%u ModelId:%u", __FUNCTION__,
			m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwCooperatorId,dwModelId);

	return 0;
}

/**
 *
 * 删除告警模版
 *
 *@param String machineKey: 机器码，必填  [in]
 *@param String source: 调用来源，必填  [in]
 *@param uint32_t sceneId: 场景id，必填  [in]
 *@param uint32_t cooperatorId: 合作伙伴ID或合作伙伴子帐号ID，必填  [in]
 *@param uint32_t modelId: 模版ID，必填  [in]
 *@param String inReserve: 请求保留字段  [in]
 *@param String errmsg: 错误信息 	[out]
 *@param String outReserve: 请求保留字段 	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::DeleteCooperatorMonitorModel(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwCooperatorId,
				uint32_t dwModelId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::string& strOutReserve
	)
{
	int32_t iRetCode = 0;

	m_dwOperatorUin=rCntlInfo.getOperatorUin();
	m_dwSceneId=dwSceneId;
	m_strMachineKey=strMachineKey;
	m_strSource=strSource;

	C2C_WW_SIM_LOG_PL_HEAD();
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oDeleteMonitorModelGroup);
	C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u dwCooperatorId:%u dwModelId:%u",
			__FUNCTION__,m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,dwCooperatorId,dwModelId);

	//基本参数校验
	iRetCode=_CheckRequest();
	if(iRetCode!=0)
	{
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	//先查一下 判断一下系统模版是不允许删除的
	//查找这个ID是否存在
	b2b2c::cooperator::po::CCooperatorMonitorModelPo oldModelPo;
	iRetCode = GetCooperatorMonitorModel(
			rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwCooperatorId,
			dwModelId,
			strInReserve,
			strErrmsg,
			oldModelPo,
			strOutReserve
	);

	//不存在这个modelid 直接返回
	if(0!=iRetCode)
	{
		return iRetCode;
	}

	//判断类型
	//系统模版不允许删除
	if(MONITOR_MODEL_TYPE_SYS == oldModelPo.GetModelType())
	{
		iRetCode = ERR_MONITORMODEL_DELETE_UNALLOWED;
		C2C_WW_LOG_ERR(iRetCode, "Unallowed Delete System Rules, OpUin:%u MachineKey:%s Source:%s SceneId:%u",
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(), m_dwSceneId);
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	b2b2c::cooperator::dao::CCooperatorDaoStub4App oCooperatorDaoStub4App;

	iRetCode = oCooperatorDaoStub4App.DeleteCooperatorMonitorModel(
			rCntlInfo,
			strMachineKey,
			strSource,
			dwSceneId,
			dwCooperatorId,
			dwModelId,
			strInReserve,
			strErrmsg,
			strOutReserve
	);

	oWTimeElf.AddTimeMark( "oCooperatorDaoStub4App->DeleteCooperatorMonitorModel", iRetCode );

	if(0!=iRetCode)
	{
		C2C_WW_LOG_ERR(iRetCode, "DeleteCooperatorMonitorModel Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s dwCooperatorId:%u dwModelId:%u",
				m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str(),dwCooperatorId,dwModelId);
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	}

	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  CooperatorId:%u ModelId:%u", __FUNCTION__,
			m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, dwCooperatorId,dwModelId);

	return 0;
}

/**
 *
 * 根据ERP商户id查询合作伙伴ID
 *
 *@param String machineKey: 机器码，必填  [in]				
 *@param String source: 调用来源，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填  [in]				
 *@param uint64_t icsonId: 易迅Id，必填  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param String errmsg: 错误信息 	[out]	
 *@param uint64_t cooperatorId: 获取到的合作伙伴ID 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CCooperatorAo::GetCooperatorIdByIcsonId(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint64_t ddwIcsonId,
				const std::string& strInReserve,
				std::string& strErrmsg,
				uint64_t& ddwCooperatorId,
				std::string& strOutReserve
	)
{
	 int32_t iRetCode = 0;
	 uint32_t dwCacheExpireTime = 0;
	 m_dwOperatorUin=rCntlInfo.getOperatorUin();
     m_dwSceneId=dwSceneId;
     m_strMachineKey=strMachineKey;
     m_strSource=strSource;

     C2C_WW_SIM_LOG_PL_HEAD();
     C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, &iRetCode, &m_oGetCooperatorIDGroup);
     C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u  IcsonId:%lu",
                __FUNCTION__,m_dwOperatorUin, strMachineKey.c_str(), strSource.c_str(),dwSceneId,ddwIcsonId);
	 
	 iRetCode=_CheckRequest();
	 if(iRetCode!=0)
	 {
		C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
		return iRetCode;
	 }
	 Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_REQ,1);
     std::stringstream ssKey;
     ssKey << ICSON_ID_CMEM_PREFIX;
     ssKey << ddwIcsonId;
     iRetCode = TMEM_CACHE_OP->GetSimpleData(ssKey.str(),ddwCooperatorId,dwCacheExpireTime);
     oWTimeElf.AddTimeMark( "TMEM_CACHE_OP->GetData", iRetCode );
	 if(0!=iRetCode)
	 	{
	 	     Attr_API2(ITIL_GET_COOPERATOR_CMEM_CACHE_ERR,1);
		     b2b2c::seller::dao::CSellerDaoStub4App oSellerDaoStub;
			 iRetCode = oSellerDaoStub.GetSellerUinByIcsonId(
			 	        rCntlInfo,
					    strMachineKey,
					    strSource,
					    dwSceneId,
						ddwIcsonId,
					    strInReserve,
						ddwCooperatorId,
						strErrmsg,
						strOutReserve
			      );
			 oWTimeElf.AddTimeMark( "oSellerDaoStub->GetSellerUinByIcsonId", iRetCode );
			 if(0!=iRetCode)
			 {
				C2C_WW_LOG_ERR(iRetCode, "GetSellerUinByIcsonId Failed OpUin:%u MachineKey:%s Source:%s SceneId:%u ErrMsg:%s IcsonId:%lu",
						m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId, strErrmsg.c_str(),ddwIcsonId);
				C2C_WW_LOG_LAST_ERR_LOG(strErrmsg);
				return iRetCode;
			 }
	 	}
	C2C_WW_LOG("%s Finished, OpUin:%u MachineKey:%s Source:%s SceneId:%u  IcsonId:%lu ", __FUNCTION__,
			m_dwOperatorUin, m_strMachineKey.c_str(), m_strSource.c_str(),m_dwSceneId,ddwIcsonId);

	return 0;

}
